views:

18

answers:

1

Is it possible to build a UI with Flash CS5 that contains multiple buttons, and then have flex listen to those button events?

My current plan is to load the SWF with SWFLoader and attaching listeners to the buttons in a onComplete event would be the proper way to set it up, however i cannot seem to find a way to access the buttons themselves and attach listeners to them. Of course i would give each button its own instance name.

Pointers and/or examples would be greatly appreciated.

+1  A: 

Once the Flash movie is loaded, you can access it from your Flex app using loader.content, where loader is the id attribute of your SWFLoader.

<mx:SWFLoader id="loader" source="Movie.swf" height="100" width="350"
   complete="onComplete()"/>

Script:

//load the clip: do this from creationComplete of the app
loader.load();

//this will be called when loading is complete
private function onComplete():void
{
    trace("loaded " + loader.content);
    var loadedMc:MovieClip = MovieClip(loader.content);
    //access the button with instance name myButton:
    loadedMc.myButton.addEventListener(MouseEvent.CLICK, onBtnClick);
}
Amarghosh