7 Replies Latest reply on Apr 21, 2010 6:58 AM by kglad

    A Simple Number Countdown

    JMillsPaysBills

      Hello all.

       

      This is my first time posting on the Adobe Forums, but I can tell you, this community has been a huge help over the years! I finally found a problem that I couldn't find the answer to by searching online, and I hope someone with some more AS2 knowledge than me can help me with it.

       

      Basically, what I'm looking to do is have a count from one number to another number over the course of 20 or 30 frames. I guess that's not important.

       

      The effect that I'm trying to achieve is this:


      I have a map animation, that I need to start at a specified date. Let's say 1900, then cycle through to 2000, then 2050, then 2100.

       

      So I have four stages of this movie.

       

      I thought it would be easy to find something like this online, but I haven't found it anywhere. I was guessing it would have to be some kind of for loop, but to be honest, my knowledge of coding isn't that great, and it's not something I could write from scratch.

       

      Does anyone have any links or references they could help me with? Maybe a nudge in the right direction? Am I completely wrong in assuming it would be a for loop?

       

      I'd like the ability to change the dates somewhere, possibly a variable.

       

      Has anyone seen something like this before?

        • 1. Re: A Simple Number Countdown
          kglad Adobe Community Professional & MVP

          for-loops and while-loops execute from beginning to end before anything is updated on-stage.  so, they can't be used to display changing values.

           

          you want to use an enterframe or setInterval() loop.

           

          this sounds so simple, you can probably get a complete answer here.  what exactly do you want to display on stage?  every integer between a start number and end number at certain time intervals

          1 person found this helpful
          • 2. Re: A Simple Number Countdown
            JMillsPaysBills Level 1

            Hi. Thanks for your quick reply.

             

            Honestly, what I'm looking for is a dynamic text box, where I can change the font.

             

            I'd like it to start at 1900, then cycle through the years until you get to 2000, then 2000 to 2050, then 2050 to 2100, within a certain number of frames. It could go every 2 or 3 years. It really doesn't matter. It's more for the effect than anything else.

             

            This might help.

             

            Here is a link to exactly what I have so far. http://ohmygraphics.com/clients/covalent/OCPR/ocpr_animation_working.html

             

            You can hit "play" and "replay" once the movie is complete.


            Eventually, I'm going to make it so you can hit "next" or "previous" and you'll see just that transition, and the dates w/ cycle through that particular stage.

             

            I've basically just created keyframes w/ the years for now, but I would like that to be dynamic, because I'm having a hard time getting the dates to sync up with the movie.

             

            What I was hoping would happen, is I could set the variables at the key frames, then have the AS figure out which years to display in between those dates, within the 30 frames.

             

            The trouble with going by a set number of steps is that it doesn't cover the same amount of years for each stage. That's why I was hoping to do something with a loop of some sort and have it spit out the numbers in between based on some calculation of the amount of frames to fill.

            • 3. Re: A Simple Number Countdown
              kglad Adobe Community Professional & MVP

              you can call the following function to cycle through numbers and display them in a textfield with instance name tf:

               

              // call displayCycleF passing the begin, end and frequency you want to update the textfield display

              displayCycleF(beginyear, endyear, frequencyinseconds);

               

               

               

              // ----------nothing below this line needs to be changed ----------------

               

              function displayCycleF(b:Number,e:Number,freq:Number){

              tf.text = b;

              clearInterval(displayI);

              increment = 1;

              displayI=setInterval(displayF,freq*1000,b,e);

              }

              function displayF(b:Number,e:Number){

              tf.text=b+increment;

              increment++;

              if(b+increment>=e){

              clearInterval(displayI);

              }

              }

              • 4. Re: A Simple Number Countdown
                JMillsPaysBills Level 1

                Kglad, Thanks so much for helping with this. Sorry I haven't replied yet, been a super busy week at work, and this got pushed to the back burner, unfortunately.

                 

                I added your code in my file, however i'm not exactly sure that it's what I was looking for.

                 

                This seems to cycle through numbers at a given interval.


                What I was hoping for was to give the script a certain number of seconds to determine what numbers to display within that given time. So for instance, if you had 2 (seconds at 24 fps) to display a range of 100, it would figure out which number to display each frame.

                 

                So, you would have 48 frames to cycle through 100 numbers. It would figure out which numbers to display. In this instance every 2.08 (rounding to the closest whole number), so basically 2 digits every frame. Except that would be calculated dynamically based on the variable "start", "end" and "range in seconds"

                 

                On closer inspections it's probably not nearly as simple as I thought it would be.

                 

                If it is simple, I'd appreciate your help. If it's not, I'll see if we have any money in the budget to write some custom scripting! Probably not though, and I'll have to end up doing it manually, unfortunately. Then change it every time the client sees it and changes their mind.

                 

                Thanks for all your help.

                • 5. Re: A Simple Number Countdown
                  kglad Adobe Community Professional & MVP

                  :

                   

                  function displayCycleF(b:Number,e:Number,seconds:Number){

                  tf.text =  b;

                  increment=1;

                  clearInterval(displayI);

                  displayI=setInterval(displayF,1000*seconds/(e-b),b,e);

                  }

                  function  displayF(b:Number,e:Number){

                  tf.text=b+increment;

                  increment++;

                  if(b+increment>=e){

                  clearInterval(displayI);

                  }

                  }

                  • 6. Re: A Simple Number Countdown
                    JMillsPaysBills Level 1

                    that's amazing.

                     

                    Works perfectly! Thank you so much. You have no idea how much time you've saved me!

                    • 7. Re: A Simple Number Countdown
                      kglad Adobe Community Professional & MVP

                      you're welcome.