Call a function in Flex from Flash at a specific frame
December 21st, 2008
There is a well known undocumented MovieClip method called addFrameScript in AS3 that is helpful when creating flash components for flex using Flash CS3 or higher.
It allows you to call a function when the playhead of the MovieClip timeline enters the specified frame number. In other words, we can call a function in flex from the flash swf file at a certain frame.
[Embed(source="../assets/swf/myFlashComponent.swf", symbol="Preloader")] private var FlashPreloaderSymbol:Class; private var clip:MovieClip; clip = new FlashPreloaderSymbol(); addChild(clip); private function onFlexInitComplete( event:FlexEvent ):void { clip.addFrameScript(47, callMyFunction); }
Format
MovieClip.addFrameScript(frame:uint,notify:Function)
We call the function “callMyFunction” when the playhead in the swf file hits frame 47.
More Resources
Flashguru’s Blog