A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Clear Interval Haywire

  1. #1
    Junior Member
    Join Date
    Jan 2006
    Posts
    24

    Clear Interval Haywire

    Hello,
    I'm working in Flash 8.
    My setInterval and clearInterval is working fine when I make a single click. When I push the call button mutiple times, the setInterval just repeats over and over. Is there something I do about this.. Thank You, Jacob


    //-------------------------<Text Animation>---------------------------\\
    var nChange:Number = 0;
    var nTimes:Number = 0;
    //to be defined later by the call function
    var nInterval:Number = undefined;

    //For Loop to Animate Text
    //50 nTimes Loops * + 2 nChange = 100 _alpha
    function setAnimate():Void {
    //Animated Property Changes
    containerMC1._alpha = nChange += 2
    //Counter
    nTimes++
    //Clears Interval
    trace(nTimes);
    if(nTimes >= 50) {
    clearInterval(nInterval);
    //Sets Loop Back...
    nChange = 0;
    nTimes = 0;
    }
    }

    //Start Interval Function
    function startInterval():Void {
    //sets TextBox Containter to alpha 0 so text change isn't visible
    containerMC1._alpha = 0;
    //No strict var so varible is global
    nInterval = setInterval(setAnimate, 10);
    }
    //-------------------------<Text Animation/>---------------------------\\

  2. #2
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    Depending on what you need, you could do a couple things...

    You could clear it before creating it, just to be sure any interval with the same identifier wouldn't continue running.
    Code:
    var nChange:Number = 0;
    var nTimes:Number = 0;
    //to be defined later by the call function
    var nInterval:Number = undefined;
    //For Loop to Animate Text
    //50 nTimes Loops * + 2 nChange = 100 _alpha
    function setAnimate():Void {
    	//Animated Property Changes
    	containerMC1._alpha = nChange += 2;
    	//Counter
    	nTimes++;
    	//Clears Interval
    	trace(nTimes);
    	if (nTimes>=50) {
    		clearInterval(nInterval);
    		//Sets Loop Back...
    		nChange = 0;
    		nTimes = 0;
    	}
    }
    //Start Interval Function
    function startInterval():Void {
    	//If the interval "nInterval" is still there clear it out.
    	clearInterval(nInterval);
    	//sets TextBox Containter to alpha 0 so text change isn't visible
    	containerMC1._alpha = 0;
    	//No strict var so varible is global
    	nInterval = setInterval(setAnimate, 10);
    }
    Or if you'd like to have the interval start, but not restart until it has finished it's first loop...

    Code:
    var nChange:Number = 0;
    var nTimes:Number = 0;
    var ifNot:Boolean = false;
    //to be defined later by the call function
    var nInterval:Number = undefined;
    //For Loop to Animate Text
    //50 nTimes Loops * + 2 nChange = 100 _alpha
    function setAnimate():Void {
    	//Animated Property Changes
    	containerMC1._alpha = nChange += 2;
    	//Counter
    	nTimes++;
    	//Clears Interval
    	trace(nTimes);
    	if (nTimes>=50) {
    		ifNot = false;
    		clearInterval(nInterval);
    		//Sets Loop Back...
    		nChange = 0;
    		nTimes = 0;
    	}
    }
    //Start Interval Function
    function startInterval():Void {
    	if (!ifNot) {
    		ifNot = true;
    		//sets TextBox Containter to alpha 0 so text change isn't visible
    		containerMC1._alpha = 0;
    		//No strict var so varible is global
    		nInterval = setInterval(setAnimate, 10);
    	}
    }

  3. #3
    Junior Member
    Join Date
    Jan 2006
    Posts
    24
    Thanks,

    The first version worked great...

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