4 Replies Latest reply on Nov 25, 2010 11:35 AM by Ned Murphy

    A Simple Math Problem

    SteveTina Level 1

      Hi guys, i am not exactly new to flash but it has been some years since I used it last. I have struck a small problem in the form of clicking a button the increments the value of a Dynamic Text field.

       

      This script is attached to a button; (Note: I am using AS2)

       

      on (press) {

      set (counter = (counter-1);

       

      }

      What set up do I need to make this work, it seems so simple on the scale of things but its something that I can't figure out.
      Thanks
      Steve

        • 1. Re: A Simple Math Problem
          Ned Murphy Adobe Community Professional & MVP

          If you are using AS2 you only need to use...

           

          on (press) {

             counter = counter-1;   // or counter -= 1;

          }

           

          If that dynamic textfield has a var attribute of "counter" assigned to it, it might work, though I avoid using the var aspect due to it acting up more often than not and just assign an instance name to the textfield and assign whatever to its text property...

           

          on (press) {

             counter = counter-1;   // or counter -= 1;

             tfName.text = counter;

          }

          1 person found this helpful
          • 2. Re: A Simple Math Problem
            SteveTina Level 1

            Thanks Ned, this is one of the many set ups I have been trying, but that doesn't seem to work either.

            help.jpgThis is what I am using at the moment, the only thing you cant see is the instance name of the Dynamic Text field which as you rightly say is called "Counter", it has no variable value.

             

            So what am I doing wrong?

            • 3. Re: A Simple Math Problem
              SteveTina Level 1

              You know what, I just solved it, it seems to be because the variable wasn't there at the start of the movie, or because they need both an instance and a variable name, does this sound right to someone or did I just get lucky?

              • 4. Re: A Simple Math Problem
                Ned Murphy Adobe Community Professional & MVP

                A variable "counter" and a textfield with an instance name "Counter"  will not be the same things.  In any case, if you have a variable, you need to have declared it.

                1 person found this helpful