7 Replies Latest reply on Mar 1, 2011 12:11 PM by Ned Murphy

    Dynamic Variables question. Need Help ASAP :(

    tofuness911

      Hi I'm new in ActionScripts and I will be using around 3000+ variables. Hard coding each variable would take up a lot of time and loading time since I would be passing these variables from a php page to my fla.

       

      Here is my code:

       

      varReceiver = new LoadVars();
      varReceiver.load("http://localhost/Syn…
      varReceiver.onLoad = function()
      {
      var DengueCasesZone;
      x = 1;
      while (x<12)
      {
      DengueCasesZone+x = Number(this.[DengueCasesZone+x]);
      x++;

       

      }

       

       

      I am passing the variable DengueCasesZone from a PHP to the flash which has the same name to be used in the flash itself


      DengueCasesZone1, DengueCasesZone2, DengueCasesZone3 til DengueCasesZone12.

      Basically, I wanted to produce 12 variables in my code above

       

      I am getting an error while executing this code that says "Left side of assignment operator must be variable or property."

       

      PS: I'm passing a string type from my php to my flash which is/should be converted into a Number.

        • 1. Re: Dynamic Variables question. Need Help ASAP :(
          Ned Murphy Adobe Community Professional & MVP

          You are targeting them incorrectly.  You use strings when using the bracket notation...

           

          varReceiver = new LoadVars();
          varReceiver.load("http://...");
          varReceiver.onLoad = function()
          {
               x = 1;
               while (x<12)
               {
                    this["DengueCasesZone"+x] = Number((this["DengueCasesZone"+x]));
                    x++;
               }

           
            // just to confirm
            x = 1;
            while (x<12)
               {
                    trace(this["DengueCasesZone"+x]);
                    x++;
               }
           
          }

          • 2. Re: Dynamic Variables question. Need Help ASAP :(
            tofuness911 Level 1

            Thank you very much sir! You're a life saver!

             

            Follow Up Question:

             

            Can I use these variables in different scenes?

            • 3. Re: Dynamic Variables question. Need Help ASAP :(
              Ned Murphy Adobe Community Professional & MVP

              I can't answer that except to say avoid using scenes if you can (I never use them)... Scenes are often problematic to implement if you incorporate navigation to get from one to another.

               

              I believe you might have to declare them as _global variables in order to do so.  Anyway, you should be able to test this yourself to find out. 

              1 person found this helpful
              • 4. Re: Dynamic Variables question. Need Help ASAP :(
                tofuness911 Level 1

                Sorry to be a burden but what do you prefer to use when navigating from a part to another? Sample codes will be much appreciated!

                 

                 

                Follow Up Question in the Dynamic Variable:

                I'm having problem implementing this. I want to use the variables I have created previously in another "scene."

                 

                Here's my code:

                 

                DengueButton.onPress = function()
                {
                x = 1;
                while(x<13)

                {
                if ("DengueCasesZone"+x <=9)
                {
                this["Zone"+x+"Green"]_visible = true;
                this["Zone"+x+"Green"]play();

                 

                }

                 

                x++;
                }

                 

                DengueCasesZoneX is the variable created previously.

                ZoneXGreen  (e.g. Zone1Green, Zone2Green, Zone3Green. etc) are Movie Clips that I want to play when the DengueButton is pressed.

                 

                 

                 

                 

                 

                Thank you sir! I'm quite a newbie in Flash and ActionScript.

                • 5. Re: Dynamic Variables question. Need Help ASAP :(
                  Ned Murphy Adobe Community Professional & MVP

                  To navigate I would either use gotoAndStop()/gotoAndPlay() or I would stay where I am and make the new section _visible ... it all depends how I approached the design.  I would either use sections of the one timeline and/or I would create each section as a movieclip instead of using scenes.

                   

                  You are still implementing the variables incorrectly.  You need to use either the bracket notation to have a string treated as an object/variable, or use the actual variable name... since you are looping and using the loop incrementer to name them, the latter is less efficient to solve for.

                   

                  if(this["DengueCasesZone"+x] <= 9)...

                  1 person found this helpful
                  • 6. Re: Dynamic Variables question. Need Help ASAP :(
                    tofuness911 Level 1

                    ["Zone"+x+"Green"]_visible = true;
                    ["Zone"+x+"Green"]play();

                     

                    The instance above ["Zone"+x+"Green"] does not seem to work with or without "this"  this["Zone"+x+"Green"]

                     

                    ["Zone"+x+"Green"] (e.g. Zone1Green, Zone2Green.... Zone12Green) is an instance of a movie clip.

                     

                    Can I make it dynamic?

                    • 7. Re: Dynamic Variables question. Need Help ASAP :(
                      Ned Murphy Adobe Community Professional & MVP

                      you need to include "this" (or some other leading object identity) as well as a dot ( . ) after the brackets...

                       

                      this["Zone"+x+"Green"]._visible = true;
                      this["Zone"+x+"Green"].play();

                       

                      If they were in some other object you could substitute that object instance name for "this", for instance...

                       

                      _root["Zone"+x+"Green"].play();

                       

                      some_mc["Zone"+x+"Green"].play();

                       

                      but you need something leading the brackets.