Results 1 to 4 of 4

Thread: The ticker countdown

  1. #1
    Join Date
    Jun 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default The ticker countdown

    Hi,

    How could i increase a number with respect to the time?

    For example ..the number should increase by certain amount per second.
    Can this be possible with the flash or action script?

    Can any one help me out.
    Thank you.

    KKG

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Are you asking about a Flash code in general that does the above?

  3. #3
    Join Date
    Jun 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yes.By using action script(I have no idea abt it).

  4. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    You're just trying to increase the value of a text field by a certain amount every second? Easy enough...

    First step up a dynamic text field on your stage. Let's give it an instance name of "theNumber". Enter whatever starting number you wish. That's all that you'll have to do on the stage. The rest is all actionscript.

    Here is the final code. I'll break it down below.
    Code:
    function countdown() {
    	theNumber.text = theNumber.text - 1;
    }
    
    setInterval(countdown, 1000);
    The workhorse function is called countdown. Basically it takes whatever is in the text field (theNumber.text) and then subtracts one from it every time it is run. The setInterval() method runs the countdown function every 1000 milliseconds (or every second).

    Thus, you have your countdown. If you're trying to do a full time countdown, it gets a little more complicated. Here is an example of what it will look like in the end. You'll need separate dynamic text fields for each unit. In this example, I've given then an instance name of days, hours, minutes, etc... The ActionScript goes a little like this:

    Code:
    function countdown() {
    	if(milliseconds.text == 00) {
    		milliseconds.text = 60;
    		seconds.text = seconds.text -1;
    	}
    	if(seconds.text < 0) {
    		seconds.text = 59;
    		minutes.text = minutes.text - 1;
    	}
    	if(minutes.text < 0) {
    		minutes.text = 59;
    		hours.text = hours.text -1;
    	}
    	if(hours.text < 0) {
    		hours.text = 23;
    		days.text = days.text -1;
    		if(days.text < 10) {
    			days.text = "0" + days.text;
    		}
    	}
    	milliseconds.text = milliseconds.text - 1;
    }
    
    setInterval(countdown, 1);
    Note: This isn't necessarily the most robust way of doing things, but it illustrates the technique. For the above to work, you'll have to set a framerate at approx. 10fps .
    Last edited by Medyman; 05-29-2008 at 08:42 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •