A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Setinterval doesn't loop back

  1. #1
    Senior Member
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    326

    Setinterval doesn't loop back

    I want to make a clip expand/shrink upon rolling over/out of a button. Also I want to control its expanding/shrinking speed, so I'm using setinterval for this. This code kinda works, but only while expanding to yscale 300. When I rollout it should shrink back to 0 again, but it looks like it jumps back and forth from 290 to 300. What am I doing wrong?

    Code:
    var i:Number = 0;
    function Increase() {
        if (i<=200) {
            clip._yscale = i;
            i = i+20;
        } else {
            clearInterval(nInterval);
        }
    }
    function Decrease() {
        if (i>0) {
            clip._yscale = i;
            i = i-20;
        } else {
            clearInterval(nInterval);
        }
    }
    //
    button.onRollOver = function() {
        var nInterval:Number = setInterval(Increase, 20);
    };
    button.onRollOut = function() {
        var nInterval:Number = setInterval(Decrease, 20);
    };

    Illustration | Animation | Web Banners | Graphic Design
    Ducklord Studio

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var nInterval:Number;
    button.onRollOver = function() {
    	clearInterval(nInterval);
    	nInterval = setInterval(Increase, 20);
    };
    button.onRollOut = function() {
    	clearInterval(nInterval);
    	nInterval = setInterval(Decrease, 20);
    };

  3. #3
    Senior Member
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    326
    I thought of that myself but it doesn't work. Tried it with this:
    Code:
    var i:Number = 0;
    Increase = function () {
    	trace(i);
    	i = i+20;
    };
    Decrease = function () {
    	i = i-20;
    };
    //
    var ID:Number;
    button.onRollOver = function() {
    	clearInterval(ID);
    	ID = setInterval(Increase, 20);
    };
    button.onRollOut = function() {
    	clearInterval(ID);
    	ID = setInterval(Decrease, 20);
    };
    But what it does when I rollover the button is it goes from 0 to up (so far so good), but on rollout I cleared the interval and started a new one which should decrease it again. But for some reason the Increase function keeps on working.

    So when I have in increased to 200 and do a rollout, it should start the Decrease function. Not tracing a value but just decreading the variable. But instead the Increase function keeps working and continuously traces 200.

    Why???

    Illustration | Animation | Web Banners | Graphic Design
    Ducklord Studio

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Still need to keep the clearIntervals in the Increase and Decrease functions.
    Code:
    var i:Number = 0;
    function Increase() {
    	if (i <= 200) {
    		clip._yscale = i;
    		i = i + 20;
    	} else {
    		clearInterval(nInterval);
    	}
    }
    function Decrease() {
    	if (i > 0) {
    		clip._yscale = i;
    		i = i - 20;
    	} else {
    		clearInterval(nInterval);
    	}
    }
    //
    var nInterval:Number;
    button.onRollOver = function() {
    	clearInterval(nInterval);
    	nInterval = setInterval(Increase, 20);
    };
    button.onRollOut = function() {
    	clearInterval(nInterval);
    	nInterval = setInterval(Decrease, 20);
    };

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