Using a button within flash movie in flex/flash builder

泪湿孤枕 提交于 2019-12-24 12:13:54

问题


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:


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);
}


来源:https://stackoverflow.com/questions/3389973/using-a-button-within-flash-movie-in-flex-flash-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!