Reputation: 1860
I have a main in .as and I load .swf in my .as.It's Working fine,Now I want the take variable From .swf and Pass it Into .as. How can i do this? pls. help! My .swf file coding
function formatMessage(chatData:Object)
{
var number:uint = chatData.user;
trace(chatData.user);
}
private function addText()
{
_loader = new Loader();
_loader.x=10;
_loader.y=200;
_loader.load(new URLRequest("receive.swf"));//Here i Can Load the Swf.Here how Can i acces the Variable of number ?
addChild(_loader);
}
Upvotes: 2
Views: 434
Reputation: 429
DisplayObjectContainer(_loader.content).getChildByName("someName");
someName variable must be public, declared in main time line, or main file.
Upvotes: 0
Reputation: 16984
First thing to keep in mind is that this will not work across ActionScript VM versions. Meaning only AVM2 and AVM2 can make communication (it is possible between AVM1, but takes more ingenuity).
Add a completion event listener to the _loader.contentLoaderInfo
property called onLoad
_loader.x=10;
_loader.y=200;
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
Now with the onLoad
function will need to extract the loaded content and a little casting.
function onLoad(evt:Event):void {
var target:DisplayObject = LoaderInfo(evt.target).content as DisplayObject; // cast as DisplayObject
trace("readMe = ", target["your_variable"]); // trace output "your_variable"
}
There are cleaner forms of getting this done, but this will allow you extract the value from the nested SWF.
Upvotes: 1