I’m programming an AS3 application which loads an external SWF file to a movie clip in my stage. I need to read a variable inside the embedded SWF. I think I can, probably, do this through the bgURL, but I can’t figure out how.
How can I read a variable inside the embedded SWF?
var bgLoader:Loader = new Loader();
var bgURL:URLRequest = new URLRequest("file.swf");
bgLoader.load(bgURL);
addChild(bgLoader);
That would be something like
trace(MovieClip(bgLoader.content).Player.played);, but make sure you access the content in the Event.COMPLETE handler:bgLoader.content returns a DisplayObject, but you need to access you content as a MovieClip. To do so you use casting.
This is presuming your external swf is also AS3 (good point Teo.sk !)
This bit:
_root.Player.playedlooks like AS2. Unfortunately you can’t accessvariables form a loaded AS2 movie directly.
Still, you can use Local Connection class to send variables back and forth betwen
AS2 and AS3. Luckily Grant Skinner wrote a nice little utility called SWFBridge
to make this easier