Groups | Blog | Home
all groups > flash actionscript > october 2007 >

flash actionscript : setting and passing variables in AS3



crila
10/24/2007 7:29:44 PM
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.
kglad
10/24/2007 7:43:53 PM
fermp
10/24/2007 7:46:31 PM
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
10/24/2007 7:52:55 PM
crila
10/24/2007 8:09:29 PM
AddThis Social Bookmark Button