# MX // Command for time peroid

**URL:** https://forum.kirupa.com/t/mx-command-for-time-peroid/25514
**Category:** flash
**Created:** [July 13, 2003, 8:44pm UTC](https://forum.kirupa.com/t/mx-command-for-time-peroid/25514 "2003-07-13T20:44:38Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![yonip](https://avatars.discourse-cdn.com/v4/letter/y/df705f/32.png) [@yonip](https://forum.kirupa.com/u/yonip)
#### Post date: [July 13, 2003, 8:44pm UTC](https://forum.kirupa.com/t/mx-command-for-time-peroid/25514/1 "2003-07-13T20:44:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 13, 2003, 9:08pm UTC](https://forum.kirupa.com/t/mx-command-for-time-peroid/25514/2 "2003-07-13T21:08:52Z")

</div>

```auto
// 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? =)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 13, 2003, 9:12pm UTC](https://forum.kirupa.com/t/mx-command-for-time-peroid/25514/3 "2003-07-13T21:12:46Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 13, 2003, 9:22pm UTC](https://forum.kirupa.com/t/mx-command-for-time-peroid/25514/4 "2003-07-13T21:22:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 13, 2003, 9:24pm UTC](https://forum.kirupa.com/t/mx-command-for-time-peroid/25514/5 "2003-07-13T21:24:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 13, 2003, 9:29pm UTC](https://forum.kirupa.com/t/mx-command-for-time-peroid/25514/6 "2003-07-13T21:29:43Z")

</div>

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

😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 13, 2003, 9:37pm UTC](https://forum.kirupa.com/t/mx-command-for-time-peroid/25514/7 "2003-07-13T21:37:12Z")

</div>

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

:hangover:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 13, 2003, 10:39pm UTC](https://forum.kirupa.com/t/mx-command-for-time-peroid/25514/8 "2003-07-13T22:39:53Z")

</div>

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