1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Small Flash Script problem (14 lines of code)

Discussion in 'Programming' started by Barti1987, Jan 11, 2008.

  1. #1
    I am trying to achieve a reverse countdown with flash scripting.

    I got up to the following code:

    
    var counter = 15;
    this.onEnterFrame = function () {
        setInterval(printime,1500);
    }
    
    function printime() {
        if(counter > 0){
            counter = string(counter - 1);
            timer_txt.text = counter;        
        } else {
            timer_txt.text = "Test";    
            stop();
        }
    }
    
    Code (markup):
    * I want it to take a second to reload each number, it does it for 15, then everything else high-speed (I couldn't find a sleep function for flash).

    * When the end comes, it shows nothing instead of "Test".

    There is a dynamic text field called timer_txt. Script is in "Action" layer and the textbox is in it is own layer (I also tried putting the script+textbox within the same layer).

    Thanks for the help beforehand,

    Peace,
     
    Barti1987, Jan 11, 2008 IP
  2. wassim

    wassim Well-Known Member

    Messages:
    322
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Hi,

    Here's the problem:

    this.onEnterFrame = function () {
    setInterval(printime,1500);
    }

    You shouldn't put the setInterval inside onEnterFrame, it should be like this:

    myInt= setInterval(printime,1500);

    then when counter reaches zero, you clear the interval with this line:


    else {

    timer_txt.text = "Test";
    celarInterval(myInt);
    stop();
    }
     
    wassim, Jan 12, 2008 IP
    Barti1987 likes this.
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Thanks for the help, +rep added.

    Peace,
     
    Barti1987, Jan 12, 2008 IP