A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: stop interval function by clicking button

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    12

    stop interval function by clicking button

    OK...Flash is making me feel really dumb.

    I have a simple movice clip, 72 frames. On Frame 42 I have this actionscript

    //----------------------------------
    function wait2() {
    stop();
    var myInterval = setInterval(function () {
    play();
    clearInterval(myInterval);
    }, 10*1000); // stop for 10 seconds
    }

    wait2();


    Also on frame 42 I have a button. I want the option of A) waiting while paused on frame 42...until my wait2() counts down and then moves to frame 43...OR option B) clicking the button which then takes me to frame 43.

    My problem. I can wait....that works fine. But if I put

    on (release) {
    nextFrame();
    }

    OR

    on (release) {
    gotoAndPlay(43);
    }

    Sure it skips to the next frame....BUT that damn wait2() function is still running....and when it's done...IT ALSO goes to frame 43 so I get this weird "loop" error.

    I've tried

    on (release) {
    wait2 = null;
    nextFrame();
    }

    and a few other "possible" solutions I found on the web....but nothing works. If I click the damn button....I end up with a weird loop issue.

    Any suggestions?

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Try declaring the interval variable outside of the function, and then calling the 'clearInterval' function when the buttons are pressed...

    On timeline...
    Code:
    var myInterval;
    function wait2() {
    	stop();
    	myInterval = setInterval(function () {
    		play();
    		clearInterval(myInterval);
    	}, 10 * 1000);// stop for 10 seconds
    }
    
    wait2();
    On buttons...
    Code:
    on (release) {
    	clearInterval(myInterval);
    	nextFrame();
    }
    //
    on (release) {
    	clearInterval(myInterval);
    	gotoAndPlay(3);
    }

  3. #3
    Junior Member
    Join Date
    Mar 2009
    Posts
    12

    working....

    Yes...that seems to have worked. Thanks.

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