5 Replies Latest reply on Oct 15, 2008 7:44 AM by Rothrock

    Global Variable Not Working?

    convrgr
      (as2/cs3)
      I'm trying to get my movie to play a closing animation then open an external swf inside it, but my global variables don't seem to work entirely.

      Then is the code calling the global variable, it loads the closing animation "start2OUT" and then at the end of that tween (on a seperate fla), there my code.

      If I click either of my city cuttons, they both goto the same location "aspenIN". Even buttons with no variable yet go to the same page, so I'm guessing it has to do with my last script. What am I doing wrong? Thank you.
        • 1. Re: Global Variable Not Working?
          kglad Adobe Community Professional & MVP
          use double equal (==) to test for equality.
          • 2. Re: Global Variable Not Working?
            convrgr Level 1
            Opps, fixed that but still it only loads the aspen page everytime... I dunno.
            • 3. Re: Global Variable Not Working?
              Rothrock Level 5
              That is because that is what you are telling flash to do. Remember it does what we tell it, not what we want.

              Okay, near the top you set both austinVar and atlantaVar, so they each have a value.

              Then when you get to the script after the tween you have an

              if(){}if else(){}else{}

              Structure. So since you have clearly set austinVar to 1, what does the first part of that conditional do? It says true. Well once a conditional tree like this starts evaluating and finds a true it doesn't do any more of the tree. Why would it? Because you can't be "else" if you are already something true.

              My guess is that you don't want to have an austinVar and atlantaVar (which are kinda bad names for variables anyways). My guess is that you want something like:

              var theCities:Array=["Austin","Atlanta","Philly"];
              var currentCity:Number=0

              And then you could do things like:

              stop();
              gotoAndPlay(theCities[currentCity]+"IN");

              or like this:

              var selectedCity:MovieClip=this["city"+theCities[currentCity]]
              selectedCity.cityfade.city.text = theCities[currentCity].toUpperCase();
              selectedCity.onRollOver = over;
              selectedCity.onRollOut = out;
              selectedCity.onRelease = function() {
              _global.currentCity = 2;
              _root.gotoAndPlay("start"+currentCity+"OUT");
              };
              • 4. Global Variable Not Working?
                convrgr Level 1
                My code is on a seperate .as file, so wouldn't it have to be a global variable? Am I supposed to call that .as at the frame label I make the code trigger to? "aspenIN" and "atlantaIN" are frame labels, so i don't think

                gotoAndPlay(theCities[currentCity]+"IN");

                will work. It's gotta call the frame label somehow.
                • 5. Re: Global Variable Not Working?
                  Rothrock Level 5
                  theCities is an array of cities and currentCity is a number representing which element (starting from zero) in that array to pick. So when currentCity is one it will find that the array holds a string called Atlanta and smash it together with "IN" and then it will go to that label. You are correct in that AtlantaIN and atlantaIN aren't the same and that is a silly mistake I just made, but I think you can see how to fix that... :)

                  As for _global, they really are not something that is needed. It is just a quick fix for not well designed scope structure. I don't use it very often and in AS3 the _global object has been removed.

                  Without knowing all the ins-and-outs of your specific project it is hard to advise you on exactly what to do. But if _global works for you in this project and you don't have the time or desire to mess it all up by trying something new...well then don't!

                  One thing that is certain is that if austinVar is equal to 1 then the code you gave will never get past the first if statement.