Turning Flash CS3 assets into Flex components – Integration of Flash and Flex using Flex Component Kit
(A Flash CS3 FLV player integrated into Flex 3)
EDIT: EXAMPLE HAS BEEN TAKEN DOWN FOR BANDWIDTH REASONS – USE THE ABOVE LINK TO VIEW SOURCE
EDIT: re: FLVPlayback component in Flex http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=13927
This is a method of taking Flash CS3 assets (whether they be flash components, timeline animations or other assets) and creating Flex components from them. These can then be used in Flex and their properties and methods accessed directly from the flex app. This allows one to exploit the advantages of Flash (there still are some advantages), and use them in the superior Flex environment. This is truly the best of both worlds.
One advantage Flash has over Flex is it’s FLVPlayback component. You have seen some methods of using this component in Flex in this blog: link
Although creating cross-talk between .swfs is useful, the method described here is far superior to the previous one for the purpose of integrating the Flash FLVPlayback component into your Flex application.
Required software:
You will need Flash CS3, Flex 2.0.1+, Adobe Extension Manager, and the extension Flex Component Kit. You can download the Flex component kit here: http://www.adobe.com/cfusion/entitlement/index.cfm?e=flex%5Fskins
you will need an adobe ID to access this page.
First Steps:
first create an actionscript file called FLVpb.as (either in a text editor or in flash) this file will reside in the same folder as the FLA you are about to create. this is a necessary step as the class name of your symbol asset must reference this file, which needs to extend UIMovieClip)
In your .as file add the following code:
package {
import flash.display.MovieClip;
import mx.flash.UIMovieClip;
import fl.video.FLVPlayback;
public class FLVpb extends UIMovieClip{
public function FLVpb(){
super();
}
}
}
1) download Flex component Kit mxp file
2) double click to install – this should automatically launch Adobe Extension Manager
3) Open Flash CS3 click new->Flash File (ActionScript 3.0) this should be named FLVpb.FLA and be saved in the same folder as your as file above.
4) click insert->new symbol create a movie clip symbol and call it ‘boundingBox’ leave the linkage fields blank
(note: in order to create a flex component, the flash asset (or assets) must all be contained within a single movieclip symbol – you can’t just drag a bunch of stuff onto the stage… create a movieclip first, then put everything inside that)
5) draw a rectangle shape inside this symbol registered at 0,0 (the reason for this bounding box will be explain later
6) click insert-> new symbol create a movieClip called FLVpb. type in FLVpb for Class and flash.display.MovieClip for base class. select Export for actionscript and Export in first frame.
7) open up the FLVpb movieClip and drag in an instance of bounding box. (it seems that without the bounding box Flex does strange things with the FLVPlayback componenet, since the buffer bar is very wide, even though it’s invisible, flex sees it and adds horizontal scrollbars on the app to accommodate it’s invisible width…) make bounding box 640px wide X 360px high (or whatever aspect ratio you will end up using – this is 16:9 widescreen)
Add a layer within the FLVpb movieclip., call it actions and insert the following code on the first keyframe (I know it’s bad form to attach code to keyframes in AS3 – so if you don’t want to , do it your way. You can also just drag an instance of FLVPlayback component from the components window – don’t forget to name it ‘myFlv’):
import fl.video.*;
var myFlv:FLVPlayback;
myFlv = new FLVPlayback();
addChild(myFlv);
myFlv.x = 0;
myFlv.y = 0;
myFlv.width = 640;
myFlv.height = 360;
myFlv.skinBackgroundColor = 0×333333;
myFlv.skinBackgroundAlpha = .6;
myFlv.skin = “SkinOverAllNoCaption.swf”;
myFlv.skinAutoHide=true;
myFlv.autoPlay=false;
myFlv.scaleMode=”exactFit”;
9) make sure the FLVpb movieclip is selected (highlighted) in the library, and click commands->make Flex components.
10) go to publish settings, and make sure ‘export swc’ is checked, then click Publish
11) put the resulting swc into some folder on your computer (I put them in one called FlashFlexSwcLibrary) this does not need to be in the folder where your other files are.
12) Launch Flex, and open a new Flex project.
13) goto Project->properties->flex build path->library path->add swc then browse to find your swc and add it to your library path.
14) you will need to add a new naamespace for this component, see the following code for this.
15) Now we will look at the flex code. It’s pretty self explanatory, so I’ll let the code to the talking. One thing to note is that I have play() for the flvPlayback component in several places (including on init) this is done for the following reason: I have autoplay set to false, since if this component was in a viewstack, and we has the creationPolicy set to “all” (my preference since not doing this creates a load lag between page changes – (I’d rather wait for everything at the beginning and have a smooth interaction from that point on), the video will start playing even if it is on an index of the viewstack which is not visible. I avoid all this by setting autoplay to false, and having control over when the vid plays. This particular example does not have this problem, but I created the swc for another project, so there you have it.
Right Click on the example for the source code. Notice how easy it is to call functions and listen for events from the Flash FLVPlayback component. It’s beautiful!
Further reading:
(Book) Flex Solutions – Essential Techniques for Flex 2 and 3 developers by: Maco Casario – friends of ed.
(web)
Special thanks to: http://www.flashcomguru.com/index.cfm/2007/7/18/flvplayback-in-flex
http://blogs.adobe.com/flex/archives/2007/04/flex_component_kit_for_flash_c.html
http://lordbron.wordpress.com/2007/05/01/flex-component-kit-step-by-step/
http://weblogs.macromedia.com/pent/archives/2007/04/example_of_the.html
http://blog.flexexamples.com/2007/09/02/installing-the-flex-component-kit-for-flash-cs3/
http://blogs.adobe.com/flexdoc/2007/08/using_the_flex_component_kit_f_1.html

Reader Comments
howdy, I’ve been trying to get this to work now for a coupla hours and getting a little frustrated at how easy it appears to be!! At step 6, when I try to create a new symbol with a base class of “mx.flash.UIMovieCLip”, I get an error saying:
“A definition for the base class could not be found in the classpath. Please enter the name of a class that is defined in the classpath, or enter the default base class ‘flash.display.MovieClip’.”
I’ve removed & reinstalled the flex component kit for flash, confirmed in Extensions Manager that v1.1.2 is installed and googled my eyes out with no answer found that matches this scenario.
Any help would be greatly appreciated!
cheers!
I’m sorry, It appears I have mislead you with an error. I went through my steps from the beginning, and found that you need to set the base class as flash.display.MovieClip. Flash then automatically changes it to mx.flash.UIMovieClip after you click commands -> convert symbol to Flex component. You can see this change if you go to the linkage window for the symbol after you create a Flex component from it. I’m sorry for the frustration, I try to keep these articles as error free as possible, but this one slipped through. Try this and let me know how it works for you.
If you still have a problem, let me know before googling your eyes out further (I know how that is), and I’ll help you get it. It’s a great tool.
P.S. I have corrected this in the article.
Mate, thank you so much! Works a treat – now I can customise away.
Thanks for the quick response and for updating the post for future vistors.
cheers!
I like how this FLV/AIR player is evolving.
I noticed that the following error message comes up when I try to click on one of the thumbnails on the right side…
Error:
“ReferenceError: Error #1069: Property repeaterIndices not found on mx.core.FlexLoader and there is no default value.
at flvPlayer/__btn2_mouseDown()”
If you could get the videos to play properly when clicking the right-hand thumbnails, this player would be awesome.
Thanks.
hmm, I’m not getting that error, they’re working fine for me. I’ll investigate…
Very simple instructions to follow up to #13. I completed this and expected to see a component under the ‘Custom’ section that never appeared. I don’t understand #14 “you will need to add a new naamespace for this component, see the following code for this.”
Am I not supposed to see a custom component that I can drag into place?
I imported your Flex Project Zip file, it works but I’m getting a few errors as well. (Same as on your site.)
Action Script Error occurs when clicking icons in listbox…
@ http://blog.flexcommunity.net/lab/flvPlayer4/ & @ http://localhost:8500/flvplayer/flvPlayer.html
ReferenceError: Error #1069: Property repeaterIndices not found on mx.core.FlexLoader and there is no default value.
at flvPlayer/__btn_mouseDown()
ALSO…
Error when clicking on Full Screen Button…
@ http://blog.flexcommunity.net/lab/flvPlayer4/ & @ http://localhost:8500/flvplayer/flvPlayer.html
SecurityError: Error #2152: Full screen mode is not allowed.
at flash.display::Stage/set displayState()
at fl.video::UIManager/http://www.adobe.com/2007/flash/flvplayback/internal::dispatchMessage()
at fl.video::UIManager/http://www.adobe.com/2007/flash/flvplayback/internal::handleButtonEvent()
ALSO…
in Flexbuilder I get the following warnings…
flvPlayer.mxml
line 40 – 1008: parameter ‘targetPath’ has no type declaration.
line 38 – 1084: var ‘i’ will be scoped to the default namespace: flvPlayer: internal. It will not be visible outside of this package.
Thanks for your help and time and putting this code out there!
Step #13 says: goto Project->properties->flex build path->library path->add swc then browse to find your swc and add it to your library path.
This means that you are selecting an swc (compiled library) to be used in your flex project. here’s the livedocs explanation: http://livedocs.adobe.com/flex/3/html/help.html?content=projects_7.html
You will not see a custom component that you can drg into place (in design view). The xml namespace refers to a declaration within the application tag that tells flex where to look for the component file when you reference it. For a regular built in component, for example, you write mx:Canvas. “mx” is the namespace. If you look inside the application tag you will see: xmlns:mx=”http://www.adobe.com/2006/mxml”
in our case we can write: xmlns:local=”*” (the asterisk means everything in the local build path. We can now insantiate the component like this: local:FLVpb
As for the warnings, they are occurring because some of the entities are not strongly typed.
As for the errors – I’m looking into these, and will correct them as soon as possible.
Thanks for the comments, and helping me get this video player up and running…
btw, the fullscreen error is because flex doesn’t allow fullscreen in the html wrapper by default. I will fix this manually at some point. If you want to do yours, and can’t wait – look here: http://blog.flexcommunity.net/lab/flvPlayer3/flvPlayer.html and view the html source…
The error occurs in both Firefox and IE6.
It appears in a large pup-up window when you try to click one of the thumbs on the right.
http://blog.flexcommunity.net/lab/flvPlayer4/
Hey guys, sorry for the delay in dealing with this, I’ve got several projects on the go. It is a priority though, I want to implement this soon.
I have been unable to repeat this error. I’ve done some research (just googling the error) and the only explanations I’ have found so far have to do with flash player (debug) versions. Here’s a typical example:
http://www.jonemerson.net/dev/articles/FlexUpgradeFromBeta.html
Although, I have to spend more time, I literally just looked for a few minutes.
Shawoody, after you click out of the error window, do the thumbnails function?
I reinstalled Flash Player 9 and I still have the same problem.
As for the thumbs, yeah the work after I “Dismiss” the error. But then I have problems with the rewind and fast-forward controls on all of the videos after that point.
I wish I was making it up… : (
That was it! The “official” Flash 9 player got rid of the error.
http://www.jonemerson.net/dev/articles/FlexUpgradeFromBeta.html
But now, sometimes the video freezes when I try to fast-forward.