4 Replies Latest reply: Oct 26, 2009 11:15 PM by faedother RSS

    Defining Variables so that MC can use them too.

    faedother Community Member

      OK I know that this is a basic question. I have variables defined in the Root directory of the flash file so that the If statement in the root directory can use them. However there are goto-statements in the movie clip right under the Root directory that also uses the same variables.  How do I define the variables so that act like 'global variables'? I mean I want to define the variables so that the code in the movie clip will use them along with the code in the root directory.

        • 1. Re: Defining Variables so that MC can use them too.
          Kalisto Community Member

          What you mean under "root directory". Is it the main timeline? If it is and you have a variable named 'test' in it you may use MovieClip( this.root ).test to get the value.

          i.e.

          something like this in main timeline;

          var test: uint = 34;

           

          and this in timeline of movieclip added into stage;

          trace( MovieClip( this.root ).test )

           

          will trace '34' in the output.

          • 2. Re: Defining Variables so that MC can use them too.
            faedother Community Member

            So that will bring the defined varables from the Main timeline into the movieclip. There for the code in the Movieclip can use the varibles with out having to redefine them in the movieclip. Correct?

            • 3. Re: Defining Variables so that MC can use them too.
              Kalisto Community Member

              In short words - "Yes"

              • 4. Re: Defining Variables so that MC can use them too.
                faedother Community Member

                 

                 

                Ok I tried that to no avail.  This is how my file is set up

                Root->Animation->Action script

                (

                stop();    var Home;  var Roster;

                function mouseDownHandlerHome(event:MouseEvent){Content.gotoAndStop(Home);

                function mouseDownHandlerEnlist(event:MouseEvent){ navigateToURL(new URLRequest("https://spreadsheets.google.com/viewform?key=psvc5aYhLuFoImejmLioWew&hl=en"));}

                function mouseDownHandlerRoster(event:MouseEvent){Content.gotoAndStop(Roster);}

                topmenu.home.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerHome);

                topmenu.Enlist.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerEnlist);

                topmenu.Roster.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandlerRoster);

                )

                |

                Content(movieclip)

                |

                Home(movieclip)-> Action Script

                (stop();

                 

                Home=1; Roster=3;

                var xmlholder:URLLoader=new URLLoader(new URLRequest("Home.xml"));

                .....

                )

                ->Roster (which has similar code)

                 

                As you can see I have a variable in the root timeline that I am defining in the embeded Movieclip.  So if there is an easy way to do a global variable or something please tell me.

                 

                NOTE: I have looked it up and people say that I would have to use a package to define a new class and then import it.  This is a problem because I am too green to know how to do that. So if that is the only way to do it, please explain the process in small simple words.

                 

                Thanks in advance.