Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flash Developer Center /

Code in Flex, test in Flash

by Tareq AlJaber

Tareq AlJaber

Content

  • Examining the new class path settings in Flash CS4
  • Testing Flex code in Flash

Created

15 February 2009

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Professional Flex integration testing

Requirements

Prerequisite knowledge

This article assumes that you have a basic understanding of Flex and some prior experience working with Flash.

User level

Intermediate

Required products

  • Flash Professional CS4 (Download trial)
  • Flex Builder 3 (Download trial)

Sample files

  • flex_to_flash.zip (7 KB)

Over the past year, Adobe received feedback from designers and developers requesting updated workflow integration between Adobe Flex 3 and Adobe Flash CS4 Professional. Users of previous versions of Flex and Flash indicated that they enjoy building projects with both programs, and would appreciate a more seamless experience when using these two powerful tools together. We listened to these requests and have responded by improving the workflow features in the release of Adobe Creative Suite 4.

The Flash and Flex teams have made many changes in the CS4 release to ensure a smooth workflow to facilitate application design and development. This article highlights one of the major advantages: the ability to develop your code in Flex and then test the project using Flash. I also describe some of the new enhancements designed to make the process of moving between Flex and Flash more intuitive than ever before.

Examining the new class path settings in Flash CS4

This section highlights some of the new workflow integration features available in Creative Suite 4. I'll begin by describing some of the new settings available in Flash CS4 Professional that make the Flash authoring environment more consistent when developing code in Flex.

Follow the steps below to review the new class path interface:

  1. Launch Flash CS4 Professional.
  2. Choose File > New > Flash File (ActionScript 3.0).
  3. Save the file (File > Save) and name it class_path.fla.
  4. Choose Window > Properties to open the Property inspector, if it is not already open.
  5. Choose File > Publish Settings, and then select the Flash tab.
  6. In the Publish Settings dialog box, click the Settings button next to the Script drop-down menu (see Figure 1).
Accessing the advanced ActionScript 3.0 settings
Figure 1. Accessing the advanced ActionScript 3.0 settings

The Advanced ActionScript 3.0 Settings dialog box appears (see Figure 2).

Advanced ActionScript 3.0 settings
Figure 2. Advanced ActionScript 3.0 settings

The interface has been revised in Flash CS4 to offer a consistent workflow for Flex developers. There are now three tabs for setting the class path, and the tab sections are organized by Source path, Library path, and External library path to mirror the setup in Flex and Flex Builder (see Figure 3).

Setting the source path information in Flex Builder
Figure 3. Setting the source path information in Flex Builder

Here's a description of the information to add in each of the three new path sections available in Flash CS4 Professional:

  • Source path: Set the source path for ActionScript files in this section.
  • Library path: Set the path to a specific SWC file or a folder containing SWC files in this section. Click the SWC icon to browse and select any SWC on your hard drive to add it to the Library path. Alternately, click the folder icon and browse to select a folder that contains multiple SWC files. This option makes it possible to add multiple SWC files to the Library path of the active SWF all at once. When you use the folder option, the path to the selected folder will display in the Library path dialog box (see Figure 4).
Path to the folder containing the SWC files
Figure 4. Path to the folder containing the SWC files

Note: If you wish to remove a path to a folder or a specific SWC file, click the minus (–) icon while the path is selected.

  • External Library path: Set the path to SWC files or folders that contain SWC files which are compiled against for definitions but are not otherwise linked into the published SWF file. This can be useful when using the "Import for runtime sharing" option for a Library item, or when loading a SWF file with a flash.display.Loader and then accessing the classes defined in the loaded SWF. In Flex Builder, SWC files and folders are put in the external Library path by expanding the tree under the file or folder in the Library path view and setting Framework Linkage to "External"—as opposed to "Merged into code" (see Figure 5).
Setting the external Library path in Flex Builder
Figure 5. Setting the external Library path in Flex Builder

You can access all three of these sections by clicking the corresponding tabs in the Advanced ActionScript 3.0 Settings dialog box (see Figure 6).

Tabs to set the class path information for the active SWF
Figure 6. Tabs to set the class path information for the active SWF

Note: The fourth tab on the right accesses the section to set Config constants. An overview of this section is outside the scope of this article, although I plan on discussing this in an upcoming article that focuses on working with these settings and conditional compilations.

Changes to the class path settings

In previous versions of Flash, the Source path was displayed as part of the global class path. In Flash CS4, the Source path is organized and displayed in its own section.

The Source path contains "." by default. By default, the Library path automatically contains:

$(AppConfig)/ActionScript 3.0/libs

The External library path contains "." as well.

These changes have been made to make Flash CS4 behave more like Flex, which does not use a global class path at all. However, the global class path in Flash CS4 is still available for use by Flash developers who have become familiar with setting the global class path and want to continue using it (see Figure 7).

Source path, Library path, and External library path separated into three sections in Flash CS4, replicating the structure used in Flex and Flex Builder
Figure 7. Source path, Library path, and External library path separated into three sections in Flash CS4, replicating the structure used in Flex and Flex Builder

Testing Flex code in Flash

In the previous section I reviewed the changes to the Advanced ActionScript 3.0 Settings dialog box and compared the new sections for setting the Source path, Library path, and External library path in Flash CS4. This is just one of the many improvements to make Flash CS4 more consistent with the workflow used in Flex.

This section covers the step-by-step instructions for testing your code created in Flex within the Flash CS4 Professional authoring environment. This is an exciting new way to build projects because you can code in Flex and then take advantage of Flash to review and test the project. If you wish to follow along, download and uncompress the sample files folder:

  • flex_to_flash.zip (ZIP, 7K)

Building the Flex project

Follow these steps to see how you can build a project in Flex:

  1. Launch Flex Builder.
  2. Choose File > New > Flex Library Project.
  3. Enter the project name FlashClass and click Finish.
  4. Right-click the project name to access the context menu. Select New > ActionScript Class.
  5. In the window that appears, enter the name of the ActionScript class: FlashClass. Also set the superclass to MovieClip (see Figure 8).
FlashClass.as file extending the MovieClip superclass
Figure 8. FlashClass.as file extending the MovieClip superclass
  1. In the Script window, copy and paste the following code inside the constructor. This code snippet uses the Drawing API to dynamically draw a rectangle vector shape:
var child:Shape = new Shape(); child.graphics.beginFill(0×003355); child.graphics.drawRect(50,100,200,100); child.graphics.endFill(); addChild(child);
  1. After adding the code, save the file. The operation of saving the file automatically generates a SWC file of the same name inside the Library folder (see Figure 9).
FlashClass.swc file automatically created and saved in the bin directory of the project file after saving the FlashClass.as file
Figure 9. FlashClass.swc file automatically created and saved in the bin directory of the project file after saving the FlashClass.as file

Testing the project in Flash

Now that you've created a small Flex project, let's see how to test that code in Flash:

  1. Launch Flash CS4 Professional.
  2. Choose File > New > Flash File (ActionScript 3.0).
  3. Choose File > Save and name the file FlashClass.fla. The location of the saved Flash file is unimportant, so you can save it in any folder you like.
  4. Choose File > Publish Settings to access the Publish Settings dialog box.
  5. Click the Flash tab to see the Flash Player and ActionScript settings.
  6. Click the Settings button next to the ActionScript drop-down menu.
  7. Click the Library Path tab.
  8. Click the red SWC icon and browse to select the SWC file named FlashClass.swc that was generated by Flex in Step 7. After you select the FlashClass.swc file, the path to the file is added to the Library path window (see Figure 10).
FlashClass.swc file path displayed in the Library path list
Figure 10. FlashClass.swc file path displayed in the Library path list
  1. Click OK to close the Advanced ActionScript 3.0 Settings dialog box and then click OK to save your changes and close the Publish Settings dialog box.
  2. Open the Actions panel by choosing Window > Actions. Since the FlashClass.fla file contains only one layer, Frame 1 of Layer 1 is automatically selected. Copy and paste the following code into the Script window to instantiate an object of FlashClass:
var flexObj:FlashClass = new FlashClass(); addChild(flexObj);
  1. Choose Control > Test Movie. The test FlashClass.swf appears and the rectangle vector shape is dynamically drawn using the code within the Flex project (see Figure 11).
Drawing API code from the Flex project displayed in the SWF file
Figure 11. Drawing API code from the Flex project displayed in the SWF file

Testing the Flex–Flash workflow

Now let's try the entire workflow to see how Flex works with Flash. You'll update the Flex code to see how the changes made to the project are automatically reflected in the Flash SWF file:

  1. Launch Flex Builder.
  2. In the Script window, update the following two lines of code with new parameters. Change the color of the vector shape and also change the width of the rectangle from 200 to 400 as follows:
child.graphics.beginFill(0×222222); child.graphics.drawRect(50,100,400,100);
  1. After updating the code, be sure to save the FlashClass.as class file. When you save the file in Flex, a new SWC file named FlashClass.swc is automatically generated, overwriting the previous version of the file in the bin folder.
  2. Return to Flash CS4 Professional.
  3. Choose Control > Test Movie. The test FlashClass.swf appears and the updated version of the vector rectangle is displayed (see Figure 12).
Updated code from the Flex project displayed in the SWF file
Figure 12. Updated code from the Flex project displayed in the SWF file

Note: The approach described above does not work when applied to the Doc class or to symbols inside the Library.

Where to go from here

To learn more about working with Flex and Flash together, read R Blank's article, Exploring a unified component workflow between Flex and Flash. Also watch the online video tutorials on the Flash channel and Flex channel on Adobe TV.

Also be sure to visit the Flash Developer Center and Flex Developer Center, where you'll find more articles, tutorials, and sample projects to get you up to speed quickly.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Creating an accessible animated presentation in Flash
  • Google Analytics for simplified tracking of rich media websites
  • Flash CS4 Missing Manual excerpts: Video, testing and debugging, optimization, and sound
  • Preventing publishing problems in Flash
  • Setting up a Flash project for local and network playback
  • Four steps to improving your Flash interface testing
  • Writing and running functional tests for Flash with Selenium RC
  • Making Flash websites searchable
  • Understanding ActionScript 3 debugging in Flash
  • Integrating Flash CS4 with After Effects CS4

Flash User Forum

More
04/23/2012 Auto-Save and Auto-Recovery
04/23/2012 Open hyperlinks in new window/tab/pop-up ?
04/21/2012 PNG transparencies glitched
04/01/2010 Workaround for JSFL shape selection bug?

Flash Cookbooks

More
02/13/2012 Randomize an array
02/11/2012 How to create a Facebook fan page with Flash
02/08/2012 Digital Clock
01/18/2012 Recording webcam video & audio in a flv file on local drive

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement