1
votes

I have a flex application and have embedded a flash (SWF) file into it using <mx:SWFLoader>. There is an "Exit" button on the Flash file. I want to be able to handle the button click event on the flex application.

So when that button in the flash file is clicked, I want to perform an action in the parent flex application. How can I do this? Thanks!

2

2 Answers

0
votes

You can do this if the event from flash "bubbles". When you dispatch the event from Flash, do this:

dispatchEvent(new Event("myEventName", true)); // that 'true' for bubbles, in the constructor

Then you should be able to capture it in Flex no problem, with:

addEventListener("myEventName", handler);

... as long as addEventListener is called on a component at or above the SWFLoader.

If you can't modify the Flash SWF, or it's a complete black box, then you can just register a MouseEvent.CLICK handler with useCapture = true, and check to see if it's the right button:

swfLoader.addEventListener(MouseEvent.CLICK, swfLoader_clickHandler, true, 0, true);

protected function swfLoader_clickHandler(event:MouseEvent):void
{
    if (event.target.name == "some_way_to_identify_the_button")
        // do X
}

Hope that helps, Lance

0
votes

You can do it using Loader Class in AS3 ( in flex script ). Even u can do it dynamically. in MXML

<mx:SWFLoader id="myLoader" width="500" source="swf/kabin42.swf"
                          complete="initSwf();"/>


private function initNestedAppProps2():void {
    var loadedMc:MovieClip = MovieClip(myLoader.content);
    loadedMc= MovieClip(myLoader2.content);
    //access the button with instance name myButton:
    loadedMc.myButton.addEventListener(MouseEvent.CLICK, onBtnClick);   
}

private function onBtnClick(event:MouseEvent):void{
    Alert.show("button clicked 2");
}

When myButton is clicked, onBtnClick event handler method will be called.. i hope, this solve your problem..