3 Replies Latest reply on May 9, 2013 12:08 PM by jbowden

    Adding amounts in edge animate

    danielwattsnbgroup

      I'm looking to create a set of buttons that would add certain numbers together.

       

      For example: If I click a button it adds the number 7 to a box, then if you click another button it adds 4 to the same box making it 11. I then want to set a variable saying if box equals 11 play animation.

       

      Is this doable in edge animate?

        • 1. Re: Adding amounts in edge animate
          elainecc Adobe Employee

          Yes, it's possible.  You can grab the value from the text box by using the jQuery html() parameter.  Let's say you have a text box on the stage called "myTextBox":

           

          var text = sym.$("myTextBox").html();

          text = text + 4;

          sym.$("myTextBox").html(text);

           

          if (text == 11) {

               sym.play();

          }

           

          -Elaine

          1 person found this helpful
          • 2. Re: Adding amounts in edge animate
            danielwattsnbgroup Level 1

            Thanks for that. It works great and in theory will do the job. One minor problem though:

             

            Applying this code to a button in edge and effecting the text box works fine but I wanted it to add the numbers together. If this code is applied, my text box shows "4". If I click again I get "44" and so on "444444" after several clicks. I'd like it to add the numbers together for example one click "4" second click "8" and third "12".

             

            Is this possible?

            • 3. Re: Adding amounts in edge animate
              jbowden Adobe Employee

              Hi there,

               

              The problem with getting html from the text element is it returns a string. In Javascript, adding a number to a string just appends the number to the existing string. To convert a string into an integer, use Javascript's parseInt method. So a slight modifcation to Elaine's code:

               

               

              // this gets the string from myTextBox and converts it to an integer

              var text = parseInt(sym.$("myTextBox").html());

              // next you are adding two integers...

              text = text + 4;

              sym.$("myTextBox").html(text);

               

              if (text == 11) {

                  sym.play();

              }

               

               

              hth,

              Joe