4 Replies Latest reply on Oct 24, 2007 1:09 PM by crila

    setting and passing variables in AS3

    crila
      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.
        • 1. Re: setting and passing variables in AS3
          kglad Adobe Community Professional & MVP
          what's the relationship between your main and child swf? eg, are you using a loader instance to load your child swf?
          • 2. Re: setting and passing variables in AS3
            fermp Level 1
            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
            • 3. Re: setting and passing variables in AS3
              kglad Adobe Community Professional & MVP
              that wasn't helpful.
              • 4. Re: setting and passing variables in AS3
                crila Level 1
                I am loading the child .swf into a movie clip on the stage.