Link to home
Start Free TrialLog in
Avatar of greg7740
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.
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);

Open in new window

Avatar of H01
H01

Hi greg7740,

just trace(MovieClip(swfLoader.content).bus_ID)  will get the variable inside the child.
Avatar of greg7740

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.
Hi greg7740,

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).innerVariable )  (<------------- should be ( innerVariable ) not bus_ID)

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.contentLoaderInfo.addEventListener(Event.COMPLETE, swfComplete);
var newID = 5;
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);

trace(MovieClip(swfLoader.content).innerVariable )

Can you see anything I'm doing wrong?  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of H01
H01

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.