greg7740
asked on
Using a Variable Outside of a function
I thought I got an answer to this earlier but I'm still having problems. I have a urlrequest that loads a variable inside of a function. I need to get the variable outside of the function so that I can use it.
I able to get the variables in the loaded swf, but If I trace them outside of the function they are null. How do I use them outside of the function.
thanks.
I able to get the variables in the loaded swf, but If I trace them outside of the function they are null. How do I use them outside of the function.
thanks.
var request:URLRequest = new URLRequest("myURL");
var swfLoader:Loader = new Loader();
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete);
var newID = 0;
function swfComplete(e:Event):void {
MovieClip(swfLoader.content).innerVariable = newID; //(<-- Pass into Loaded swf)
newID = MovieClip(swfLoader.content).bus_ID;//(Pass Back to Main swf
}
swfLoader.load(request);
ASKER
HI H01
It traces fine inside the function and I get the variable. But when I trace outside of the function, I get Error #1009: Cannot access a property or method of a null object reference.
Unless I'm not tracing it correctly.
thanks.
It traces fine inside the function and I get the variable. But when I trace outside of the function, I get Error #1009: Cannot access a property or method of a null object reference.
Unless I'm not tracing it correctly.
thanks.
Hi greg7740,
That is the correct way to do it, you must be missing something out, can you post your code.
That is the correct way to do it, you must be missing something out, can you post your code.
Hi greg7740
I think is the variable name in the loaded swf, may be you refer to an undefine varible.
trace(MovieClip(swfLoader. content).i nnerVariab le ) (<------------- should be ( innerVariable ) not bus_ID)
I think is the variable name in the loaded swf, may be you refer to an undefine varible.
trace(MovieClip(swfLoader.
ASKER
Hi Ho1
This error I get: Error #1009: Cannot access a property or method of a null object reference.
this is my code:
stop();
var request:URLRequest = new URLRequest("http://www.myURL.com/busLogin/loaderTest.swf");
var swfLoader:Loader = new Loader();
swfLoader.contentLoaderInf o.addEvent Listener(E vent.COMPL ETE, swfComplete);
var newID = 5;
function swfComplete(e:Event):void {
MovieClip(swfLoader.conten t).innerVa riable = newID; //(<-- Pass into Loaded swf)
newID = MovieClip(swfLoader.conten t).bus_ID; //(Pass Back to Main swf
}
swfLoader.load(request);
trace(MovieClip(swfLoader. content).i nnerVariab le )
Can you see anything I'm doing wrong? Thanks.
This error I get: Error #1009: Cannot access a property or method of a null object reference.
this is my code:
stop();
var request:URLRequest = new URLRequest("http://www.myURL.com/busLogin/loaderTest.swf");
var swfLoader:Loader = new Loader();
swfLoader.contentLoaderInf
var newID = 5;
function swfComplete(e:Event):void {
MovieClip(swfLoader.conten
newID = MovieClip(swfLoader.conten
}
swfLoader.load(request);
trace(MovieClip(swfLoader.
Can you see anything I'm doing wrong? Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if you place your trace inside the swfComplete funtion - if your variables are correct that should be fine.
you shoul as h01 is saying only be trying to access the content from swfLoader when it's finished loading.
you shoul as h01 is saying only be trying to access the content from swfLoader when it's finished loading.
just trace(MovieClip(swfLoader.