MX // Command for time peroid

Hi I have a question. Say I want to increase the x postion for a object for 5 seconds, how would I do this? Ive been looking at gettimer / setinterval on the forums but still do not understand. Thanks

// define an onEnterFrame handler to move the MovieClip continuosly
clip.onEnterFrame = function() {
	this._x++;
};
// delete the onEnterFrame handler after 5 seconds
var deleteOnEnterFrame = setInterval(function () {
	delete clip.onEnterFrame;
	clearInterval(deleteOnEnterFrame);
}, 5000);

does that help? =)

getTimer() is basically the timer, in milliseconds of the duration the movie has been playing. If you call getTimer() 1 second after the movie’s been playing, it will read 1000, after 2 seconds, 2000, etc. This is the function you want to use to move the object for 5 seconds. Stick this code in your object and i’ll explain after:

onClipEvent (load) {
startTime = getTimer();
}
onClipEvent (enterFrame) {
if (getTimer() - startTime < 5000) {
_x = _x+5;
}
}

This code tells the object to move 5 pixels to the right for 5 seconds. startTime is the variable defined as the time which the object begins calling its code. The “getTimer() - startTime < 5000” says, for the next 5 seconds, do the following code. getTimer is always increasing in milliseconds, so if you compare it to the start time by taking the difference between the two, you can essentially give it a duration.

without trying to think too much I’d say you could do something like this…

location=this._x;
getTimer() = curTime;
while (getTimer()-5000 < curTime) {
this._x = location+i++;
};

Code’s probably not right since I’m not big on actionscripting but that should give you an idea.

oh, and it’s 5000 for 5 seconds b/c I believe getTimer() returns miliseconds.

Hope it helps

haha, when I started writing that, there were no replys

shouldn’t that be curTime = getTimer();?

:wink:

*Originally posted by awligon *
**Code’s probably not right since I’m not big on actionscripting but that should give you an idea.
**

:hangover:

hey, whatever effort you put is still effort. you helped and that’s all that matters.