?
Solved

Using a Variable Outside of a function

Posted on 2009-06-26
7
Medium Priority
?
390 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

770 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