I’ll show you step by step how this new kit works.
Now, I know all the hype about Open Source has everyone’s attention. However, the Flex Component Kit for Flash CS3 is the bigger news in my opinion. It’s going to take some time before we see the fruits of the Open Source project. The kit, however, is going to deliver some beautiful eye-candy, very quickly. Everyone needs to give a big thanks to Glenn Ruehle (Glenn, start a blog!) and Ely Greenfield for making this wonderful little tool. Now, you can see Glenn give a nice demo of this here, and you should watch it cuz Glenn can deliver himself a mean connecto (breezo). You can also read the instructions that come with the kit, and you should cuz it makes things clear. However, if you don’t want to do either, here’s a little step by step with screenshots and SWFs to help you understand.
First and foremost you need to install Flash CS3, the Flex Component Kit and prep Flex Builder. Go check out the Labs site for that info.
We’re eventually going to build this simple app. As you can see, it’s just a simple ball component that grows and shrinks. Now, the neat thing here is that you’re not just going to be building and seeing the finished product. You’re going to be seeing the various levels of the kit. You’ll come to see how labels become states, how animations become transitions and how the boundingBox works and why. The beauty and true power of the kit is not clear until you see AND understand all those pieces.
The path I’m taking is complete newbie on both Flash CS3 and Flex Builder 2. Each step has a number, the app to use, a corresponding image and a series of substeps. The image is to help you visualize the substeps and has red “highlights” to show emphasis.
Warning: This little experiment is not for the faint of heart. It is quite lengthy. I promise though, by the time you’re done, you’ll know why the kit is so exciting. Sorry for the crappy Step 1.1 style. I wanted and wrote Step 1.A and so on, but WordPress doesn’t want to keep the Letter list type. Let’s get started.
Step 1: Draw the BlueBall
App: Flash CS3
Step 1 Image
- Switch to the Oval Tool (Top Red Rectangle on Tool Palette on Step 1 Image)
- Pick Black for the Stroke Color and Blue for the Fill Color. (Bottom Red Rectangle on Tool Palette on Step 1 Image)
- Draw a circle on stage. You can hold the “Shift” key down to maintain a perfect Circle. Make sure it’s big enough so you can shrink it later (Mine is 174 pixels)
Step 2: Convert drawing to symbol
App: Flash CS3
Step 2 Image
- Select the entire image and in the “Modify” menu, choose “Convert to Symbol…” (Top Red Shape on Step 2 Image)
- In “Convert to Symbol” dialog box, make sure “MoviClip” is selected and name the symbol “BlueBall”. Leave all other settings alone.
- Click “OK”. This adds the “BlueBall” symbol permanently to your library while leaving a “copy” of that symbol on the stage.
Step 3: Clear Stage and Create Empty BallComponent Symbol
App: Flash CS3
Step 3 Image
- After the symbol is created, select the blue ball on the stage canvas and delete it. The stage should be empty now. Note: This just deletes a “copy” of the symbol.
- Verify that the BlueBall symbol is in your library. (Lower Red Rectangle on Step 3 Image) If it’s not, start over.
- Now that the canvas is empty, in the “Insert” menu choose “New Symbol…”.
- This will open up the “Create New Symbol” dialog box.
- Name the new symbol “BallComponent”. Leave all other settings alone.
- Click “OK”. This adds the blank “BallComponent” symbol directly to your library.
Step 4: Add BlueBall to BallComponent
App: Flash CS3
Step 4 Image
- Click on “BlueBall” symbol in the “Library Panel”. (Small Red Rectangle on Step 4 Image)
- While still holding the mouse button down, drag the symbol onto the white canvas and release the mouse button. (Large Red Square on Step 4 Image)
- Drag the “BlueBall” symbol on the stage and move it towards the center of the canvas. (Red Arrow on Step 4 Image)
- Align the black cross-hair (aka plus sign aka registration point) of your “BlueBall” symbol to the cross-hair in the center of the stage. They should overlap completely and appear as one. (Small Red Square on Step 4 Image)
Flex expects the registration point to be the top-left corner of the component.
Step 5: Rename Layer and Add a Keyframe
App: Flash CS3
Step 5 Image
- In the timeline, double click the text “Layer 1” and replace it with “BlueBall”. (Red Rectangle on Step 5 Image)
- Right click on frame 25 for the “BlueBall” layer and pull up the pop up. (Red Square on Step 5 Image)
- Choose “Insert Keyframe”. Note: Be sure to choose correctly and do NOT choose “Insert Blank Keyframe”.
Step 6: Animate BlueBall
App: Flash CS3
Step 6 Image
- Verify you’re still on Frame 25, the pink playhead should be on Frame 25. (Check against Step 6 Image)
- Click on the “BlueBall” symbol on the canvas.
- Make sure “Constrain” is checked in Transform Panel. Note: If you do not see the Transform Panel, in the “Window” menu choose “Transform”.
- Change the value of the height or width from “100.0%” to “50.0%”. (Red Rectangle on Step 6 Image)
- Right click on Frame 24 or lower on the “BlueBall” layer and choose “Create Motion Tween”.
Step 7: Create Flex Project
App: Flex Builder 2
Step 7 Image
- From the File Menu choose “New” then “Flex Project”. (See Step 7 Image for visual aid)
- Select “Basic” for “How will your Flex App access data?”. (Top Red Square on Step 7 Image)
- Give “BallTest” as your project name. (Bottom Red Square on Step 7 Image)
- Write down the default location. It will be in the “Flex Builder 2” directory, which by default Flex Builder puts in your “Documents” (Mac) or “My Documents” (Windows).
- Click “Finish”. This will create then open up the BallTest.mxml file.
Step 8: Set Frame rate and Export BallComponent
App: Flash CS3
Step 8 Image
- Click on some white space on the canvas. (Small Upper Red Square on Step 8 Image)
- This will show the Document properties, which includes the Frame rate.
- Change the Frame rate from “12” to “24”. (Lower Red Rectangle on Step 8 Image)
- In the “Commands”menu, choose “Make Flex Component”. Note: This will add the UIComponent clip to your library.
- Right click on “BallComponent” in the Library Panel. Note: Do not right click on “BlueBall” in the library.
- In the pop up, choose “Export SWC File…”. Note: Popup is moved in Step 8 Image for demo purposes. (Red arrow from Library on Step 8 Image)
- Browse to your Flex Builder 2 “BallTest” directory and name the file “BallComponent.swc”. (Large Red Square on Step 8 Image)
Step 9: Modify Layout and Add 2 Buttons
App: Flex Builder 2
Step 9 Image
Step 9 SWF
- In the mx:Application tag, change the value of the layout property from “absolute” to “horizontal”.
- Add a button with the label property value of “Make Small”.
- Add a second button with the label property value of “Make Big”. (Finished code is visible on Step 9 Image)
- Run the application. (It should look like Step 9 SWF) The buttons don’t do anything yet and there’s no BallComponent.
Step 10: Add BallComponent.swc to BallTest Project
App: Flex Builder 2
Step 10 Image
- Right click on the BallTest Project folder in the Navigator Panel.
- Choose “Properties”.
- In the “Properties for BallTest”, choose the “Flex Build Path” on the side. Note: This is NOT the section open by default. (Big Red Square on Step 10 Image)
- Click the “Add SWC…” button. (Small Red Rectangle on Step 10 Image)
- Browse to the “BallTest” project directory and select “BallComponent.swc”
- Click “OK”.
Step 11: Add BallComponent tag to BallTest Application
App: Flex Builder 2
Step 11 Image
Step 11 SWF
- Note: The one sad thing that images and text cannot show is how nice these next steps are. You can start to type “BallComponent” in the editor and it should create the following code for you.
- Add the: xmlns:local=”*” property to the application tag.
- Add the <local:BallComponent/> tag between the two buttons. (Added code is highlighted in blue on Step 11 Image)
- Run the application. (It should look like Step 11 SWF)
If you’ve made it down this far, congrats. This is where it starts to get fun! Yeah, it was pretty boring up to that point. Sorry, but it was needed so that we could have some files to work with. At this point in the project, we see how Flex auto loops the animation from Flash. The animation is of the ball shrinking, never growing. This is because we’re seeing frame 1 to frame 25, over and over. We also see how Flex is constantly updating the width of the BallComponent to match the constantly changing ball animation.
Step 12: Stopping the Loop
App: Flash CS3
Step 12 Image
Step 12 SWF
- Add a new layer to the BallComponent Timeline. (Click the icon in the Small Red Square on Step 12 Image)
- Rename the layer “ActionScript”. (See step 5A if you don’t remember how to rename a layer)
- Right click on Frame 1 in the ActionScript layer.
- Choose “Insert Keyframe”. (All the above steps on one half of Step 12 Image, all the below steps on the other half)
- Click on Frame 1, then in the “Window” menu choose “Actions”.
- Type the code: Stop();
- Close the “Actions” Panel.
- Re-export the BallComponent.swc to the BallTest Flex directory. (See steps 8.6 & 8.7 if you don’t remember how to export the component)
- Re-run the Flex Application. (It should look like Step 12 SWF)
When you build your Flex app this time, you’ll notice that the looping is gone. This is because we specifically added the code “Stop();” to Frame 1.
Step 13: Adding Flash Frame Labels
App: Flash CS3
Step 13 Image
- Add a new layer to the BallComponent Timeline. (See step 12.1 if you don’t remember how to add a new layer)
- Rename the layer “State Labels”. (See step 5.1 if you don’t remember how to rename a layer)
- Right click on Frame 1 in the State Labels layer.
- Choose “Insert Keyframe”.
- Click on Frame 1 in the State Labels layer.
- In the Properties Panel, make the Frame Label equal “big”. (Steps 13.3 to 13.6 on one half of Step 13 image)
- Right click on Frame 25 in the State Labels layer.
- Choose “Insert Keyframe”. (See steps 12.3 and 12.4 if you don’t remember how to add keyframes.)
- Click on Frame 25 in the State Labels layer.
- In the Properties Panel, make the Frame Label equal “small”. (Steps 13.7 to 13.10 on the other half of Step 13 image)
- Re-export the BallComponent.swc to the BallTest Flex directory. (See steps 8.6 & 8.7 if you don’t remember how to export the component)
Step 14: Using Labels as States in Flex
App: Flex Builder 2
Step 14 Image
Step 14 SWF
- Add the value “myFlashBall” to id property of the BallComponent tag.
- On the “Make Small” button, add this code to the click event: myFlashBall.currentState=’small’;
- On the “Make Big” button, add this code to the click event: myFlashBall.currentState=’big’;
- Re-run the Flex Application. (It should look like Step 14 SWF)
Playing with this SWF, you can see how the frame labels from Flash automatically turned into states in Flex for that component. No extra code needed from us to create those states. A Flash Frame Label = Flex Component State. We just point them out in our code. How sweet is that? Ah, but what about that animation we have on the timeline? Can’t we use that? We sure can.
Step 15: Adding transition labels
App: Flash CS3
Step 15 Image
- Add a new layer to the BallComponent Timeline. (See step 12.1 if you don’t remember how to add a new layer)
- Rename the layer “Transition Labels”. (See step 5.1 if you don’t remember how to rename a layer)
- Right click on Frame 1 in the Transition Labels layer.
- Choose “Insert Keyframe”.
- Click on Frame 1 in the Transition Labels layer.
- In the Properties Panel, make the Frame Label equal “big-small:start”. (Steps 15.3 to 15.6 on one half of Step 13 image)
- Right click on Frame 25 in the Transition Labels layer.
- Choose “Insert Keyframe”. (See steps 12.3 and 12.4 if you don’t remember how to add keyframes.)
- Click on Frame 25 in the Transition Labels layer.
- In the Properties Panel, make the Frame Label equal “big-small:end”. (Steps 15.7 to 15.10 on the other half of Step 13 image)
- Re-export the BallComponent.swc to the BallTest Flex directory. (See steps 8.6 & 8.7 if you don’t remember how to export the component)
Step 16: Adding transition code
App: Flex Builder 2
Step 16 SWF
- NO ADDITIONAL CODE!
- Re-run the Flex Application. (It should look like Step 16 SWF)
As you can see, just be adding another set of labels in Flash you automatically get transitions in Flex. This requires no other code input into the Flex file. As long as you follow the convention of: {StartingFrameLabel}-{EndingFrameLabel}:start and {StartingFrameLabel}-{EndingFrameLabel}:end. Not only that, but the Component Kit is smart enough to use one animation in two different directions (big to small and small to big). That, to me, is just pure genius.
This is because of how Flex tries to find transitions. From the docs, Flex searches for frame labels that match the view state change in the following order:
- currentViewState-destinationViewState (no wildcards)
- currentViewState-destinationViewState (reversed)
- *-destinationViewState
- *-destinationViewState (reversed)
- currentViewState-*
- currentViewState-* (reversed)
- *-*
You can swap out the term StartingFrameLabel for currentViewState and EndingFrameLabel for destinationViewState. Those terms make more sense to me since you have to add the “:start” and “:end” suffixes to the start frame and end frame, respectively.
There is only one thing left though; That is the auto resizing of the Flex component during Flash resizing animation. We want Flex to keep using the same width, regardless of state or transition.
Step 17: Adding a bounding box
App: Flash CS3
Step 17 Image
- Add a new layer to the BallComponent Timeline. (See step 12.1 if you don’t remember how to add a new layer)
- Rename the layer “BoundingBox”. (See step 5.1 if you don’t remember how to rename a layer)
- Click on any frame in the BoundingBox layer.
- Choose the rectangle tool. (Wide Red Rectangle on Tools Panel on Step 17 Image)
- Find Stroke Color and Fill Color. (Tall Red Rectangle on Tools Panel on Step 17 Image)
- Choose “Black” as the Stroke color and make the Fill Color is the white box with red strike, i.e. “invisible”. (Follow the colors on Step 17 Image )
- Draw a square that is the size and height you want your Flex component.
- Select the entire BoundingBox image and in the “Modify” menu, choose “Convert to Symbol…”. (Note: Make sure you only have the box selected and not the blue ball.)
- After the symbol is created, click on it.
- Type “boundingBox” as the Instance name. (See Small Red Box at bottom of Step 17 Image)
- Re-export the BallComponent.swc to the BallTest Flex directory. (See steps 8.6 & 8.7 if you don’t remember how to export the component)
Step 18: Adding boundingBox code
App: Flex Builder 2
Step 18 SWF
- NO ADDITIONAL CODE!
- Re-run the Flex Application. (It should look like Step 18 SWF)
The reason why you don’t need any additional code in your Flex file is because again of the kit. Flex will look for a movieclip with the name of “boundingBox”. When it finds it, then it uses that as the set width and height of your application.
I hope this post turns out to be helpful for those who are wondering about the kit. I can’t wait to try some more advanced stuff with the kit. When I do, I’ll post them here to my blog as well.
For those who want the “Solution” code, here is a zip of the completed Flash CS 3 fla file and the completed Flex Builder 2 Project.