[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Using a Variable Outside of a function

Posted on 2009-06-26
7
Medium Priority
?
394 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:greg7740
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 4

Expert Comment

by:H01
ID: 24726291
Hi greg7740,

just trace(MovieClip(swfLoader.content).bus_ID)  will get the variable inside the child.
0
 

Author Comment

by:greg7740
ID: 24726643
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.
0
 
LVL 4

Expert Comment

by:H01
ID: 24726738
Hi greg7740,

That is the correct way to do it, you must be missing something out, can you post your code.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:H01
ID: 24726771
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)

0
 

Author Comment

by:greg7740
ID: 24728629
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.
0
 
LVL 4

Accepted Solution

by:
H01 earned 2000 total points
ID: 24730036
Hi greg7740,

The problem is you are tracing the innnerVariable before the load function completely load the inner swf, thats why AS3 cant find the varible so giving you the error.

You can create a button and wait until the inner swf have successfully loaded then only u click on the button to trace the innerVariable.

Hope this helps you out.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 24730314
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.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question