AS 2 How do i do this timer?
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: How do i do this timer?

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    3

    How do i do this timer?

    Code:
    _root.timer1 = 200;
    
    
    countdown = function ()
    {
    	_root.timer1--;
    	if (_root.timer1 == 0){
    		clearInterval(countdownInterval);
    	}
    }
    stop();
    
    countdownInterval = setInterval(countdown, 250);
    I'm on "stage1" and die, then i goto "gameover" stage and press the replay button. (it's a game)
    And now this code above is being executed 2 times, it goes twice as fast as i should do. Any help here?

    Sorry, I'm new and trying to learn.

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    936
    It works fine on my side. I used "traces" to test your script. The timer start to increase until 0, then it stops and executes the code above the clearInterval.
    I think you issue has to do with your .fla, some movieclip, some frame, some other code...

    What it's supposed to happen before, while and after the timer?
    Hi Object, Listen, i wish to return you something, but only if what you are saying is true, else, forget it, ROLL_OVER the floor, i will check for someone else at the stage, while eating a no.visible cookie.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    When i complete the level 1 map, another script takes the time and print it in the end screen ( not the "gameover" screen). That works fine.
    But if I die, I go back to the "info screen" and press ready. Then I goto Level 1 and the timer go twice as fast.

    You can find the game at my website here

    Want to have the .fla file?

  4. #4
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    936
    Yeah send me the fla please. It would be better if I see what i'm doing hehe!
    Hi Object, Listen, i wish to return you something, but only if what you are saying is true, else, forget it, ROLL_OVER the floor, i will check for someone else at the stage, while eating a no.visible cookie.

  5. #5
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    936
    Ok! I think i know where is the issue. Your game at your site helped me have a clear vision of the situation. Let me work on it
    Hi Object, Listen, i wish to return you something, but only if what you are saying is true, else, forget it, ROLL_OVER the floor, i will check for someone else at the stage, while eating a no.visible cookie.

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    936
    In the script when you die that then you are redirected to the "play again" frame, put this:
    PHP Code:
    _root.clearInterval(countdownInterval); 
    That fix your problem my friend


    Explanation: The countdownInterval will only be cleared when the timer reaches 0. When you die, the timer will keep counting...so each time you replay the game, the timer multiplies its speed. You need to clear the interval when dying. (Dying is the script where it detects when the characters runs out of HP/lifes, or when it falls down)

    Or if you have a lot of ways for the character to die, then put the clearInterval script on the "play again" frame.
    Last edited by angelhdz; 12-04-2012 at 08:44 AM.
    Hi Object, Listen, i wish to return you something, but only if what you are saying is true, else, forget it, ROLL_OVER the floor, i will check for someone else at the stage, while eating a no.visible cookie.

  7. #7
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    936
    But it's better that you ckeck all your dying ways in one if statement, Eg:

    PHP Code:
    //if my character falls down, OR if my character's HP/life is iqual to 0, OR if my character hit the BIG BOSS,
    if(myCharacter._y>Stage.height || myCharacter.HP==|| myCharacter.hitTest(_root.BigBoss)){

    //then go to and stop try again frame and clear the timer interval
    _root.clearInterval(countdownInterval);
    gotoAndStop("try again frame")

    Hi Object, Listen, i wish to return you something, but only if what you are saying is true, else, forget it, ROLL_OVER the floor, i will check for someone else at the stage, while eating a no.visible cookie.

  8. #8
    Member
    Join Date
    Aug 2012
    Posts
    50
    I think is meaning

    Code:
    clearInterval(_root.countdownInterval);

  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thank you! It worked.
    It's my first "game" in flash and it's not so organized. I don't think I can put all the "dying ways" in one if statment. But I will keep that in mind when i work on the new, more organized one. This one was just for practices.

    Thanks again!

  10. #10
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    936
    Quote Originally Posted by Terrencing View Post
    I think is meaning

    Code:
    clearInterval(_root.countdownInterval);
    You're right, i put the _root in the wrong place. Hehe.
    Hi Object, Listen, i wish to return you something, but only if what you are saying is true, else, forget it, ROLL_OVER the floor, i will check for someone else at the stage, while eating a no.visible cookie.

Posting Permissions

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




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com