4 Replies Latest reply: Jan 14, 2013 12:00 PM by Ned Murphy RSS

    Need help creating a count-up animation

    chris heyes Community Member

      HI. I'm new (ish) to FlashCS6 and need help creating a count up animation. I'm fine with general flash animation, but have never really used action script, so do need my hand holding a bit. any help would be great.

       

      Basically I have 12 scenes depicting someone going about their daily life buying items and at the end of each scene I have a little cash graphic that pops up - I then need to numbers to quickly animate counting eg, from £0 to £369 over a couple of seconds.

       

      thanks in advance

       

      Chris

        • 1. Re: Need help creating a count-up animation
          Ned Murphy CommunityMVP

          You aren't likely to get your hand held without showing something of an effort to solve things yourself, but here's something to start with.  Your cash graphic will need to be a MovieClip or Sprite so that you can target it using code.  Let's say you assign that an instance name of "cashGraphic".  Inside of it you will have a dynamic textfield that you also need to name, so let's call that "cashDisplay"

           

          YOu will also need some variable somewhere in the main timeline that holds the total cash value... let's call that variable cashTotal

           

          To get it to gradually update the value to the final amount, the end of each scene will need to have code such as the following (assuming an AS3 solution)...

           

          stop();

           

          cashGraphic.addEventListener(Event.ENTER_FRAME, tallyCash);

           

          var cashValue = -1;  // will be used to count up from 0 to cashTotal

           

          function tallyCash(evt:Event):void {

               cashValue += 1;

               cashGraphic.cashDisplay.text = "£"+String(cashValue);

               if(cashValue == cashTotal){

                    cashGraphic.removeEventListener(Event.ENTER_FRAME, tallyCash);

               }

          }

          • 2. Re: Need help creating a count-up animation
            moccamaximum Community Member

            Here is a good tutorial that explains the needed steps in detail:

            http://www.snorkl.tv/2010/09/how-to-tween-a-variable-with-flash-and-tweenlite/

             

            You need to install TweenLite

            • 3. Re: Need help creating a count-up animation
              chris heyes Community Member

              Thanks very much for your help - managed to get it up and running!

              Only problem is I need the total to include 2 decimal places (its a cash total, i.e. £26.60)

              Any ideas how I achieve this? at the moment using the integer it only counts whole numbers and if I remove it it shows as '£26.6' instead of '26.60'

               

              thanks again

              • 4. Re: Need help creating a count-up animation
                Ned Murphy CommunityMVP

                The toFixed() method should do what you need.  Per my earlier sample code....

                 

                cashGraphic.cashDisplay.text = "£"+cashValue.toFixed(2);

                 

                 

                The toFixed method returns a String value so you don't need to cast it as one in the coding like I showed earlier.