Home > Adobe Flash, Adobe Flex & AIR, Design > Call function from Flex to Flash

Call function from Flex to Flash

How to call a flash function from flex?

  1. Load the AS3 swf file using an instance of SWFLoader.
  2. Call the function like this:
mySWFLoader.content.functionName();

How to listen for flash events from flex?

  1. // In your Flex app
    /* called when your SWFLoader finishes loading the SWF */
    private function onMySWFLoaded( p_event:Event ) :void
    {
          mySWFLoader.content.addEventListener( “clicked”, onSWFClick );
    }

    /* callback for the clicked event */
    private function onSWFClick( event:Event ) :void
    {
          mx.controls.Alert.show( ‘Click event raised!’ );
    }

  2. // In Flash Movie
    /* called when the button in your flash movie is clicked */
    private function onButtonClick( p_event:Event ) :void
    {
          dispatchEvent( new Event( “clicked” );
    }

How to call a flex function from flash at a specific 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);
}



Bookmark and Share
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogosphere News
  • LinkedIn
  • Live
  • MySpace
  • Tumblr
  • TwitThis
  • Yahoo! Buzz
  • StumbleUpon
  • Technorati
  1. amutha
    October 30th, 2009 at 12:06 | #1

    hi.. i have flash cs3 swf and i loaded that swf in flex through swfloader..

    i wrote event for clicking in swf its working good… but i cannot call particular symbol of the swf in flex ..its show the following error while using symbol in loader….
    “unable to resolve ‘/babyadop.swf’ for transcoding”

  2. December 10th, 2009 at 00:56 | #2

    This is because you are not allowed to address/access stage variables.

  1. No trackbacks yet.