# Moving and stop

**URL:** <https://forum.kirupa.com/t/moving-and-stop/2883>\
**Category:** Uncategorized\
**Created:** [March 14, 2002, 7:05pm UTC](https://forum.kirupa.com/t/moving-and-stop/2883 "2002-03-14T19:05:14Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [March 14, 2002, 7:05pm UTC](https://forum.kirupa.com/t/moving-and-stop/2883/1 "2002-03-14T19:05:14Z")

</div>

Hi! All,\r\rI put the following script in a MC and have the MC moves gradually from left to right:\r\ronClipEvent (load) {\r speed = 2;\r&nbsp &nbsp &nbsp &nbsp startX = this.\_x;\r}\ronClipEvent (enterFrame) {\r&nbsp &nbsp &nbsp &nbsp this.\_x = this.\_x+speed;\r&nbsp &nbsp &nbsp &nbsp if (this.\_x\>500) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this.\_x = startX;\r&nbsp &nbsp &nbsp &nbsp }\r}\r\rNow, I want the MC moves a short distance, say 100 pixels, and stops for a while, say 5 seconds, and again moves and stops…\r\rThanks for anybody help me on this.\r\rJames

---

<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:** [March 14, 2002, 7:21pm UTC](https://forum.kirupa.com/t/moving-and-stop/2883/2 "2002-03-14T19:21:42Z")

</div>

Use an if condition combined with a function using getTimer; getTime at start, save in var, get again in the function and check the difference against the value you want, when value is reached, move again…i know this is kinda short, you ok with actionscript? (btw, timer gets milliseconds, don’t forget the conversion -5secs=5000millisecs)

---

<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:** [March 14, 2002, 11:11pm UTC](https://forum.kirupa.com/t/moving-and-stop/2883/3 "2002-03-14T23:11:23Z")

</div>

Thanks eyezberg,\r\rPer your advise, I revised my script as follows:\r\ronClipEvent (load) {\r\_ \_ \_ \_ \_ \_ \_ \_ speed = 2;\r startX = this._x;\r}\ronClipEvent (enterFrame) { \r\r_ \_ \_ \_ for (i=1; i\<4; i++){\r\r\_ \_ \_ \_ \_ \_ \_ \_ this._x = this.x+speed;\r\r \_ \_ \_ \_ \_ \_ \_ \r_ \_ \_ \_ \_ \_ \_ \_ if (this._x==100+(i-1)\*100){\r_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ currentTime = int(getTimer()/1000);\r\_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ if ((time+5)\<=currentTime) {\r speed=0;\r\_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ time = currentTime;\r\_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ }\r\r\_ \_ \_ \_ \_ \_ \_ \_ }\r\r if (this.\_x\>500) {\r this._x = startX;\r }\r_ \_ \_ \_ }\r}\r\rI just want to stop at 100, 200, and 300. I know my “for loop” is not properly placed. Could give me some advise. Also I can’t stop the MC even I put a “if loop”. There should be something wrong. Appreciate your help.\r\rJames

---

<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:** [March 16, 2002, 3:07am UTC](https://forum.kirupa.com/t/moving-and-stop/2883/4 "2002-03-16T03:07:45Z")

</div>

Hi, All,\r\rI now work from other direction and the MC can move about 2 sec and then strop for about 3 sec…The script is as follows:\r\ronClipEvent (enterFrame) {\r&nbsp &nbsp &nbsp &nbsp if (\_root.delay) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this.\_x += 2;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp if (int(getTimer()/1000) \> \_root.lastTime+1) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_root.delay = false;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this.\_x += 0;\r\r&nbsp &nbsp &nbsp &nbsp }\r&nbsp &nbsp &nbsp &nbsp } else if (int(getTimer()/1000) == \_root.lastTime+5) {\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_root.lastTime = int(getTimer()/1000);\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_root.delay = true;\r&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \r&nbsp &nbsp &nbsp &nbsp }\r}\r\rHowever, I don’t know how to control the MC to stop at every 100 pixels. Appreciate if anybody can help me…

---

<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:** [March 17, 2002, 6:39pm UTC](https://forum.kirupa.com/t/moving-and-stop/2883/5 "2002-03-17T18:39:33Z")

</div>

Maybe make sure \_x is 0 onLoad (so +2 eventually gets you to 100, 200…) and nest another if (this.\_x=i), right before you set up a loop for(i=100;i\<whateverYouNeed;i+=100)…\rPost the result once e’thing works 😉

---

<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:** [March 18, 2002, 6:57am UTC](https://forum.kirupa.com/t/moving-and-stop/2883/6 "2002-03-18T06:57:10Z")

</div>

Thanks for reply.\r\rIt will be no problem to get 100,200,…if I set x +=1; or move the MC starting position. The problem is that I really don’t know where to put the “for loop” and “if clause”. I tried to put them as follows but it doesn’t work.\r\ronClipEvent (enterFrame) {\r\rfor (i=100;i\<whateverYouNeed;i+=100){\r if (_root.delay) {\r\r_ \_ \_ \_ \r this.\_x += 1;\r\r \_ \_ \_ \_ \_ \_ \_ \_ if (this.\_x=i){ \r \r if (int(getTimer()/1000) \> \_root.lastTime+1) {\r \_root.delay = false;\r this._x += 0;\r_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ \_ }\r }\r } else if (int(getTimer()/1000) == \_root.lastTime+5) {\r \_root.lastTime = int(getTimer()/1000);\r \_root.delay = true;\r \r }\r}\r}
