Skip to main content
Inspiring
October 24, 2007
Question

setting and passing variables in AS3

  • October 24, 2007
  • 4 replies
  • 599 views
I need to set and pass a variable to an embedded .swf. I know setting a variable looks like this:

var iknow:int;
iknow = 20;

This just sets the variable on my main .swf. How do I send it down so the child .swf recognizes it too?

Thanks in advance for any suggestions.
This topic has been closed for replies.

4 replies

crilaAuthor
Inspiring
October 24, 2007
I am loading the child .swf into a movie clip on the stage.
kglad
Community Expert
Community Expert
October 24, 2007
that wasn't helpful.
Inspiring
October 24, 2007
I think what you need to do is use a global variable. Do a search in Flash help for "Understanding variable scope"

The following is a snippet from the help section:

The scope of a variable is the area of your code where the variable can be accessed by a lexical reference. A global variable is one that is defined in all areas of your code, whereas a local variable is one that is defined in only one part of your code. In ActionScript 3.0, variables are always assigned the scope of the function or class in which they are declared. A global variable is a variable that you define outside of any function or class definition. For example, the following code creates a global variable strGlobal by declaring it outside of any function. The example shows that a global variable is available both inside and outside the function definition.

var strGlobal:String = "Global";
function scopeTest()
{
trace(strGlobal); // Global
}
scopeTest();
trace(strGlobal); // Global
kglad
Community Expert
Community Expert
October 24, 2007
what's the relationship between your main and child swf? eg, are you using a loader instance to load your child swf?