dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: AS2. while loop, setInterval, clearInterval problem

Hybrid View

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    7

    AS2. while loop, setInterval, clearInterval problem

    I'm trying to get my code working so effectively the playhead moves backwards for a certain length of time (20 frames, 1 frame every 33 milliseconds). The setInterval function works when not inside the WHILE but I need it to run 20 times and then use the clearInterval function to stop it. I can't seem to figure out how to solve it. Currently it outputs 1 through to 20 and then "clear interval". Can someone please give me a hand? here is the code which is inside an onRelease button holder. Thanks to anyone with input.

    var myInterval = setInterval(slow, 33);
    var counter = 0
    while (counter < 20) {

    counter++;
    trace(counter);

    function slow (){
    trace("slow function");
    prevFrame();
    }
    }
    clearInterval(myInterval);
    trace("clear interval");

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    on (release) {
    	clearInterval(myInterval);
    	var myInterval = setInterval(slow, 33);
    	var counter = 0;
    	function slow() {
    		if (counter<20) {
    			counter++;
    			trace(counter);
    			trace("slow function");
    			prevFrame();
    		} else {
    			clearInterval(myInterval);
    			trace("clear interval");
    		}
    	}
    }

  3. #3
    Senior Member
    Join Date
    Mar 2000
    Posts
    116
    /nod
    Webpages:

    www.winningsolutionsinc.com

  4. #4
    Junior Member
    Join Date
    Jun 2009
    Posts
    7
    Beautiful, thanks so much.

Tags for this Thread

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