PDA

View Full Version : Passing variables from classes to swfs



thatguythatsme
April 14th, 2008, 11:15 AM
Hello all,

I'm having trouble passing variables from an class which is loading this data from an xml file to a swf that this class is also loading.

I want the swf file to use the some of the data contained in the main class.

At the moment I can' seem to see a way of doing this, I haven't used AS3 or Flash in a few months either which isn't helping.

I'm able to load the swf fine from the xml but I still haven't figured out how to compile the swf file without getting errors because the variables it needs are in the class...

Any help with a show in the right direction would be great.

Dave

thatguythatsme
April 14th, 2008, 01:20 PM
Never mind, figured it out now, didn't think I could use loaderInfo to retrieve vars from a string in the AS, thought it was just for use to collect vars in the html string on the html page...

Quick example for anyone interested.

Load the swf in my class...


var loader:Loader = new Loader();
addChild(loader);
var swf:URLRequest = new URLRequest(mainXMLData.loadAppSrc(0) + "default.swf?myLocation="+_currentSrc);
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, initListener);
loader.load(swf);


Retrieve the vars via loaderInfo in my swf



var dynamicLoc:String = loaderInfo.parameters.myLocation;
try {
trace(dynamicLoc);
} catch (error:Error) {
trace("Error catch :: " + error);
}


Dave