Flash Component Kit Flex3
Flash Component Kit Flex3
Contents
Installing the Adobe Flex Component Kit for Flash CS3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
About importing Flash CS3 assets into Flex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Using Flash components in a Flex application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Adding view states and transitions to Flash components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Using Flash components as skins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Creating a Flash container component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
System requirements
Your system must meet the following requirements to install the Flex Component Kit for Flash CS3:
• Flex 3
• Flash CS3 Professional
• Adobe Extension Manager. You can download the Extension Manager from
http://www.adobe.com/exchange/em_download/.
Installation procedure
The Flex Component Kit for Flash CS3 consists of the FlexComponentKit.mxp file.
<mx:Script>
<![CDATA[
// Embed the SWF file and the symbols from the SWF file.
[Embed(source="../assets/circlesquare.swf")]
[Bindable]
public var LogoCls:Class;
<!-- Load the SWF file by using the Image control. -->
<mx:Image source="{LogoCls}"/>
ADOBE FLEX 3 3
<!-- Load the SWF file as the icon for a Button control. -->
<mx:Button icon="{LogoCls}" height="100" width="200"/>
<!-- Load the BlueSquare symbol as the icon for a Button control. -->
<mx:Button icon="{LogoClsBlueSquare}" height="100" width="100"/>
<!-- Load the GreenCircle symbol as the icon for a Button control. -->
<mx:Button icon="{LogoClsGreenCircle}" height="100" width="100"/>
For a container, run Commands > Convert Symbol to Flex Container to convert your symbol to a subclass of the
ContainerMovieClip class and to configure the Flash CS3 publishing settings for use with Flex. For more infor-
mation, see “Creating a Flash container component” on page 18.
4 Publish your FLA file as a SWC file.
5 Reference the class name of your symbols in your Flex application as you would for any class. For more infor-
mation, see “Compiling a Flex application that uses a Flash component” on page 7.
6 Include the SWC file in the library-path option when you compile your Flex application. For more infor-
mation, see “Compiling a Flex application that uses a Flash component” on page 7.
UIMovieClip implements the interfaces necessary for a Flash component to be used like any other Flex component.
Therefore, you can use a subclass of UIMovieClip as a child of a Flex container or as a skin, and it can respond to
events, define view states and transitions, and work with effects in the same way as any Flex component.
The mx.flash.ContainerMovieClip is a subclass of the UIMovieClip class. When you create a container in Flash, you
create the container as a subclass of the ContainerMovieClip class.
When you install the Flex Component Kit for Flash CS3, you also install the install_dir\frame-
works\projects\flash_integration\libs\FlexComponentBase.swc file. This SWC file contains all of the information
necessary to use the UIMovieClip class in Flash.
For more information on the UIMovieClip and ContainerMovieClip classes, see Adobe Flex Language Reference.
If you have Flash content that requires a different registration point, you can wrap the symbol in another
symbol with an upper-left registration point. For more information, see “Positioning a Flash component in
a Flex container” on page 8.
6 Select the movie clip symbols in the Library panel.
7 Select Commands > Convert Symbol to Flex Component.
This command converts the symbol into a subclass of the UIMovieClip class, and configures the publishing
settings of your FLA file for use with Flex. For more information, see “Actions performed by the Convert Symbol
to Flex Component command” on page 6.
The Convert Symbol to Flex Component prompts you to set the frame rate of the FLA file to match the default
Flex frame rate, which is 24 frames per second. Although you can set the frame rate to a different value, setting
it to less than 24 frames per second can make the Flex application appear sluggishness.
After you run this command, a FlexComponentBase compiled clip appears in the Library panel of your Flash
application.
8 Select File > Publish to create the SWC file.
The output SWC file is named ButtonSkins.swc.
Note: Instead of using the Convert Symbol to Flex Component command, you can manually configure a symbol to be
used as a Flex component by making all of the settings described in this section. However, before you can reference the
UIMovieClip class, you must open the Components panel and drag the FlexComponentBase component into the Library
panel.
<myComps:MyButtonUpSkin/>
<myComps:MyButtonOverSkin/>
<myComps:MyButtonDownSkin/>
<myComps:MyButtonDisabledSkin/>
</mx:Application>
In this example, you use the Flash components to skin the Button control and use the components as stand-alone
Flex components. To use a Flash component as a stand-alone Flex component, the main application file must include
a namespace definition. The namespace tells Flex where to look for the file that implements the component. By
default, Flash creates the class that corresponds to your Flash component in the default package, corresponding to a
namespace of "*".
If you define a package name for your Flash component, you must specify the namespace accordingly. For example,
suppose you define the package name for your Flash component as the following example shows:
package flashComponents {
// Component definition
}
In this example, the SWC file is in the SWF9SWC directory. From the example in the section “Creating a Flash
component for a Flex Button skin” on page 4, the SWC file is named ButtonSkins.swc.
Setting focus
For a Flash component, the individual Flash symbols in the component can receive focus if they set the tabEnabled
property to true. Focus is indicated by the standard yellow highlighting of Flash Player. To control the appearance
of the focus highlighting, handle the focusIn and focusOut events for the associated Flash symbol.
In a Flash container, only the Flex components in the content area of the Flash container can receive focus. The Flex
components use the standard Flex highlighting to display focus. However, Flash symbols in the Flash container
cannot receive focus. For more information on creating a Flash container, see “Creating a Flash container
component” on page 18.
ADOBE FLEX 3 9
// EventBlueSquare.as
import mx.flash.UIMovieClip;
import flash.events.Event;
[Event(name="blueSquareSelected", type="flash.events.Event")]
<mx:Script>
<![CDATA[
<myComps:EventBlueSquare id="myBS"
blueSquareSelected="handleBlueSquareSelected();"/>
<mx:TextArea id="myTA"/>
</mx:Application>
For more information on defining custom events, see “Custom Events” on page 23 in Creating and Extending Flex
Components.
ADOBE FLEX 3 10
You can also set the tool tip in MXML when you use the component in a Flex application, as the following example
shows:
<?xml version="1.0"?>
<!-- embedSWF9/EmbedSWF9ToolTip.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:myComps="*">
<myComps:EventBlueSquare id="myBS"
toolTip="MXML Tooltip"/>
</mx:Application>
For more information on tool tips, see “Using ToolTips” in Flex Developer’s Guide.
One way to control the size of a Flash component is to add a bounding box to the component. The bounding box is
a MovieClip instance that Flex uses to size the Flash component at run time. Within the area of the bounding box,
the Flash component can perform animations or modify its visual characteristics. But, as long as the area of the
bounding box does not change, Flex does not resize the component.
The following image shows a Flash component named StatesGreenOval with three view states:
A B C
D
The rectangle surrounding the green oval is the movie clip symbol that corresponds to the bounding box. As the
green oval rotates, it stays within the area defined by the bounding box, so Flex does not attempt to resize it.
The UIMovieClip class defines a property named boundingBoxName that specifies the bounding box MovieClip for
the Flash component. The default value of the boundingBoxName property is "boundingBox". Therefore, you
typically specify "boundingBox" as the instance name of the bounding box MovieClip. If you use a different instance
name for the MovieClip, ensure that you set the boundingBoxName property to that name.
The Convert Symbol to Flex Component command sets the visible property to false for the MovieClip that
represents the bounding box so that it does not appear in your Flex application.
// Set the number of visble dots at run time based on the size
// Flex passes to the component at run time.
override public function
setActualSize(newWidth:Number, newHeight:Number):void
{
if (newWidth != _width || newHeight != _height)
{
_width = newWidth;
_height = newHeight;
addChild(dot);
dot.x = col * (SIZE + GAP);
dot.y = row * (SIZE + GAP);
}
}
}
}
}
}
Note: The class must be defined as public to be used in Flex.
Use the DotPattern component in a Flex application, as the following example shows:
<?xml version="1.0"?>
<!-- embedSWF9/EmbedSWF9SetActualSize.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%" height="100%"
xmlns:myComps="*">
The following image shows a Flash component named StatesGreenOval with three view states:
A B C
D
In the Flex application, you change the view state of the component by setting its currentState property to the
frame label, as the following example shows:
<?xml version="1.0"?>
<!-- embedSWF9/EmbedSWF9ViewStates.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:myComps="*">
<myComps:StatesGreenOval id="myOval"/>
Adding transitions
A Flash component can define an animation that plays during a view state change, where the animation corresponds
to a Flex transition. For example, if the change of view state alters the color, size, or other visual aspect of the
component, the transition animates that change.
To define an animation in a Flash component that corresponds to a Flex transition, you create two key frames and
associated frame labels. The first key frame marks the beginning of the animation, and the second key frame marks
the end. The frame labels must adhere to the following naming convention:
• Beginning key frame: currentViewState-destinationViewState:start
• Ending key frame: currentViewState-destinationViewState:end
For example, if the name of the current view state is BaseState, and the name of the destination view state is Ninety,
the frame labels for the associated key frames of the transition must be:
BaseState-Ninety:start
BaseState-Ninety:end
When you change the view state of the Flash component from BaseState to Ninety, Flex automatically looks for frame
labels that define the beginning and end of the transition and, if found, plays the associated animation. When you
switch back from the view state Ninety to BaseState, Flex automatically looks for frame labels in the form:
Ninety-BaseState:start
ADOBE FLEX 3 15
Ninety-BaseState:end
If found, Flex automatically plays the animation. If these labels are not found, Flex plays the animation for the
BaseState to Ninety transition in reverse.
You can use the wildcard symbol, "*", when specifying the frame label, where the wildcard symbol corresponds to
any view state. For example, the frame label BaseState-*:start specifies a transition from the BaseState view state
to any other view state. The frame label *-BaseState:start specifies a transition from any view state to BaseState.
Flex searches for frame labels that match the view state change in the following order:
• currentViewState-destinationViewState (no wildcards)
• destinationViewState- currentViewState (reversed)
• *-destinationViewState
• destinationViewState-* (reversed)
• currentViewState-*
• *-currentViewState (reversed)
• *-*
This list shows that Flex searches first for frame labels with no wildcards, both forward and reverse, before checking
for frame labels that use wildcards. Then, Flex searches for a frame label that uses a wildcard for the current view
state, both forward and reverse, followed by a search for a frame label that uses a wildcard for the destination view
state. Lastly, Flex searches for a frame label that uses wildcards for both the current and destination view states.
The following image shows a green oval in Flash CS3:
Layer 2 Defines the following two key frames and frame labels for the transition from the BaseState view state to the
FortyFive view state:
BaseState-FortyFive:start
Layer 3 Defines two key frames, frame labels, and a motion tween for the transition from the BaseState view state to
the Ninety view state. The motion tween defines the animation that plays when you change view states. The frame
labels are:
BaseState-Ninety:start
Layer 4 Defines two key frames and frame labels for the transition from the FortyFive view state to the Ninety view
state:
FortyFive-Ninety:start (not shown in the image)
The following Flex application uses the transition when changing view state:
<?xml version="1.0"?>
<!-- embedSWF9/EmbedSWF9ViewStatesTrans.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:myComps="*">
</mx:Application>
upSkin up mx.skins.halo.ButtonSkin
You can create a Flash component that defines a stateful skin for one, two, or more states of the Button control.
Each view state of a Flash component corresponds to a specific key frame and frame label. For example, to create a
component with four view states, you define four key frames and add a frame label to each key frame. For more infor-
mation on creating view states in a Flash component, see “Adding view states and transitions to Flash components”
on page 13.
Note: The frame label of the view state in the Flash component must match the state name of the Flex component. The
state name is typically the name of the corresponding skin property, without the word "skin". For example, in the previous
table for the Button control, the skin property downSkin defines the skin for the down state of the Button control.
ADOBE FLEX 3 18
The following image shows a Flash component named StatefulButtonSkin with four view states; up, down, over, and
disabled, that correspond to four states of the Button control:
The view states each define a different color for the Button control, in the same way as did the skins in the section
“Creating a Flash component for a Flex Button skin” on page 4.
After publishing the SWC file that contains the definition of the StatefulButtonSkin component, use the component
in your Flex application, as the following example shows:
<?xml version="1.0"?>
<!-- skins/EmbedSWF9StatefulButtonSkins.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
The rectangular region of a container encloses its content area, the area that contains its child components. The size
of the region around the content area is defined by characteristics of the container, such as the padding and the width
of the container border. The following image shows a container and its content area, padding, and borders:
A B
A. Left padding B. Right padding C. Container D. Content area E. Top padding F. Bottom padding
The primary use of a container is to arrange its children, where the children are either controls or other containers.
The following image shows a simple Panel container that has three child components:
You can create Flex container in Flash CS3, which lets you define the appearance of the container in Flash, including
the characteristics of the container padding and boundaries, and then use the container in Flex to add Flex compo-
nents to the container’s content area.
Create a Flex container in Flash CS3 much in the same way that you create a Flex component. First, define a movie
clip symbol for the container, then use the Convert Symbol to Flex Container command to convert the symbol to a
subclass of the mx.flash.ContainerMovieClip class. You then add the FlexContentHolder symbol to your container
to define the container’s content area.
ADOBE FLEX 3 20
<myComps:MyPictureFrameContainer>
<mx:HBox
width="100%" height="100%">
<mx:Image
source="../assets/logowithtext.jpg"
width="80%" height="80%"/>
</mx:HBox>
</myComps:MyPictureFrameContainer>
</mx:Application>
<mx:Script>
<![CDATA[
import mx.containers.HBox;
import mx.controls.Image;
<myComps:MyPictureFrameContainer id="pFrame"
initialize="init();"/>
</mx:Application>
A ResizeArrow Defines the icon use to collapse the container. The arrow points down when the container is expanded, and to
the right when it is collapsed. Click the arrow to minimize the container, and click it again to restore it to its original
size.
E ContentArea Defines the white background for the area in which you place Flex controls.
F FlexContentArea Defines the area for the Flex components. This area is sized to match the size of the ContentArea.
ADOBE FLEX 3 23
To add the animation to the container, you use view states. The states layer defines the following two view states:
expanded The container displays in its full, expanded size, and the resize arrow points down.
collapsed The OuterArea, ContentArea, and FlexContentArea collapse to the size of the TitleBar, hiding all of the
Flex components in the FlexContentArea. The resize arrow points to the right.
Note: You should never remove the FlexContentHolder symbol from a frame of your Flash container. To hide the
FlexContentHolder symbol, set its height and width properties to 0, or set its alpha property to 0.
To handle the state change in response to a click on the arrow, you write the following class file for the ResizablePan-
elContainer class. This class defines an event handler for the ResizeArrow that changes the current view state of the
container in response to a mouse click:
package {
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import mx.flash.ContainerMovieClip;
// Constructor
public function ResizablePanelContainer()
ADOBE FLEX 3 24
{
ResizeArrow.addEventListener(MouseEvent.CLICK, arrowHandler);
ResizeArrow.useHandCursor = false;
}