all groups > flash actionscript > april 2007 >
You're in the

flash actionscript

group:

set Interval


set Interval fourinchesofego
4/29/2007 3:49:21 PM
flash actionscript:
Hello...

I have written a small function that simply moves an object to a new position
on stage depending on a variable passed to the function. It works just fine,
but instantly rather than in intervals -- mimicking a tween. I was wondering
how I would integrate a delay into this function to allow it to work in
increments.

The function is as follows:
function moveIt(thePosition) {
while (theName._x != thePosition) {
if (theName._x<thePosition) {
theName._x += 5;
} else if (theName._x>thePosition) {
theName._x -= 5;
}
}
}

Can I use set Interval? If so, how? Would I strip out the while loop to do so?

Help would be greatly appreciated.

Thanks
Re: set Interval dr_ross
4/30/2007 12:00:00 AM
At a guess of what you're after something like this should help

function moveIt(thePosition) {
//while (theName._x != thePosition) {
if (theName._x<thePosition) {
theName._x += 5;
} else if (theName._x>thePosition) {
theName._x -= 5;
}
//}
}
my_interval = setInterval(this,"moveIt",100,100);

where the first 100 is the millisecond gap between calls, the second is the
position parameter passed to the function

to stop the interval call clearInterval(my_interval);
AddThis Social Bookmark Button