A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: timer weird behavior

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    9

    timer weird behavior

    Hi, I have 3 frames and I need to switch between them after 5 seconds. My AS2.0 code for every frame is:

    function myTimee (){
    gotoAndStop(2);
    }

    setInterval(myTimee,5000);


    of course, function name and frame in gotoAndStop changes every time. The weird thing is that it works for the very first time, but then it is going crazy.

    1.2.3.
    2. // here it goes to frame 2 instead of 1

    3.1.2.3.1.2.3.1.2.3.
    2. // this is weird too
    3.1.2.3.1.
    Thank you


    .fla attached
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    cant open your fla.
    you need to clearIntervals otherwise you will have more and more intervals running at the same time and consequently giving you odd behaviour.

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    9
    Quote Originally Posted by gorlummeeguvnor View Post
    cant open your fla.
    you need to clearIntervals otherwise you will have more and more intervals running at the same time and consequently giving you odd behaviour.
    thank you, gorlummeeguvnor. That .fla is CS5 version, I uploaded CS4 version. Hope that helps. Anyway, I know that i have to somehow end that interval, but I dont know if I'm doing it right. This is my code in each frame..

    var myInterval = setInterval(myHello2, 2000);

    function myHello2 (){
    gotoAndStop(2);
    }
    setInterval(myHello2,5000);

    clearInterval(myInterval);
    Attached Files Attached Files

  4. #4
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    i only have cs3.
    give intervals individual names.
    first frame :-
    Actionscript Code:
    stop();
    function myHello2 (){
    gotoAndStop(2);
    }
    myInterval1 = setInterval(myHello2,2000);

    clearInterval(myInterval);

    second frame
    Actionscript Code:
    stop();
    clearInterval(myInterval1);
    function myHello2 (){
    gotoAndStop(3);
    }
    myInterval2 = setInterval(myHello2,2000);

    third frame
    Actionscript Code:
    stop();
    clearInterval(myInterval2);
    function myHello2 (){
    gotoAndStop(1);
    }
    myInterval3 = setInterval(myHello2,2000);

    try that - works ok for me

  5. #5
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    hmm - or does it?

  6. #6
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    oops. try this
    frame1
    Actionscript Code:
    stop();
    function myHello2 (){
    gotoAndStop(2);
    clearInterval(myInterval1);
    }
    myInterval1 = setInterval(myHello2,5000);
    frame2
    Actionscript Code:
    stop();
     function myHello2 (){
    gotoAndStop(3);
    clearInterval(myInterval2);
    }
    myInterval2 = setInterval(myHello2,1000);
    frame3
    Actionscript Code:
    stop();
    function myHello2 (){
    gotoAndStop(1);
    clearInterval(myInterval3);
    }
    myInterval3 = setInterval(myHello2,1000);

    the alternative is to use setTimeOut - which i believe runs an interval once only

  7. #7
    Junior Member
    Join Date
    Nov 2010
    Posts
    9
    This works like swiss watch! Thank you very much for your time..

  8. #8
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    a pleasure - sorry about the guff though. as a point of interest setInterval will never be like a swiss watch - it is not a great timer in terms of accuracy.

  9. #9
    Junior Member
    Join Date
    Nov 2010
    Posts
    9
    Quote Originally Posted by gorlummeeguvnor View Post
    a pleasure - sorry about the guff though. as a point of interest setInterval will never be like a swiss watch - it is not a great timer in terms of accuracy.
    I think chinese watch for 3 bucks will be enough for me Thanks again. You already solved 50% of my problems, if you have few minutes, here is the second one:

    I have few buttons with simple animation where it disappears(alpha=0) and appears and I need to fix two things. When cursor is still over that button, I need to play animation only once. This I have done (I dont know if it was the best way, but it somehow works. And the second, if that button is down (animation is playing) and I roll out and then roll on again, the animation start from the beginning and it looks bad.

    My english is not so good, so, here is the link
    http://nettrans.sk/flash/MYS_OK.html

    So, when it is white and cursor flows over, it blinks with blue animation of disappearing. I need to keep it white.. Thank you.

  10. #10
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    any chance you could post the fla - i have cs3 or earlier versions

  11. #11
    Junior Member
    Join Date
    Nov 2010
    Posts
    9
    ok, here is .fla CS3 version. Thanks!
    Attached Files Attached Files

  12. #12
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    you seem to be working in as3 in this fla. is this correct? if so i cant help you. if you want to do it in as2 then i probably can.

  13. #13
    Junior Member
    Join Date
    Nov 2010
    Posts
    9
    Yes, its AS3, sorry I didnt mentioned that. But its not important if it will be AS2 or AS3.

  14. #14
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    not quite sure what you are after so have a look at this and tell me what needs changing
    Last edited by gorlummeeguvnor; 04-19-2011 at 04:32 PM.

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