Flex/Air Accessing movieclip in loaded swf
In one of my latest’s works, I had to use two different swfs and Flex to interact between them. For example, I had some movie clips in one swf, and in other I had some visual text that I wanted to show on click in one of the movie clips. Cause the information that I found wasn’t so god, here is a example how can you do it.
What do you really have to do is initialize the movie clips and functions inside of each swf, and then you can use them as you which.
Create 2 swf (I used Flash). In one we have a movie clip that I called BtnClick and in the second one I have a label with visibility set to false, and a function in that allow me to show the label.
TxtHello.visible = false;
TxtHello.visible = true;
Second: In Flex, use swfLoader to load your content and then initialize the movie clips and the functions that you made is Flash :
private var loaderContent1:Object;
private var loaderContent2:Object;
protected function InitMovieClips(event:Event):void
var BtnClick:SimpleButton = SimpleButton(loader1.content["BtnClick"]);
loaderContent2 = loader2.content;
protected function ShowHelloWorldText(event:MouseEvent):void
<!– Place non-visual elements (e.g., services, value objects) here –>
<mx:SWFLoader id="loader1" source="assets/Loader1.swf" complete="InitMovieClips(event)"/>
<mx:SWFLoader id="loader2" source="assets/Loader2.swf" complete="InitMovieClips(event)"/>
Link to the project
And that’s it…
Hope you enjoy