# Slowing down

**URL:** <https://forum.kirupa.com/t/slowing-down/117186>\
**Category:** Uncategorized\
**Created:** [July 25, 2004, 3:19pm UTC](https://forum.kirupa.com/t/slowing-down/117186 "2004-07-25T15:19:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mad\_man](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mad\_man](https://forum.kirupa.com/u/mad_man)\
**Post date:** [July 25, 2004, 3:19pm UTC](https://forum.kirupa.com/t/slowing-down/117186/1 "2004-07-25T15:19:16Z")

</div>

hello,  
i am new to flash and i was wondering if there is a way to slow down for loops.  
Like i can set how many seconds till it goes and loops again. I have tried setInterval but didnt work.here is my code:

on (press) {  
enemmyX = this.\_x;  
enemmyY = this.\_y;  
for(starX = \_root.star1.\_x;starX\>enemmyX; starX–){

\_root.star1.\_x = \_root.star1.\_x-1;

// Slow down function here  
}  
}

help will be appreciated.

---

<div class="post-metadata">

**Author:** ![2nd\_day](https://avatars.discourse-cdn.com/v4/letter/2/a4c791/32.png) [@2nd\_day](https://forum.kirupa.com/u/2nd_day)\
**Post date:** [July 25, 2004, 6:23pm UTC](https://forum.kirupa.com/t/slowing-down/117186/2 "2004-07-25T18:23:33Z")

</div>

it has to be something with setInterval… so maybe this works:

```auto

on (press) {
	setInterval(function() {
		enemmyX = this._x;
		enemmyY = this._y;
		for (starX=_root.star1._x; starX>enemmyX; starX--) {
			_root.star1._x = _root.star1._x-1;
			// Slow down function here
		}
	}, 1000);
}

```

maybe it doesn’t because i’m not very formiliar with the setInterval function, but im just trying to help

---

<div class="post-metadata">

**Author:** ![2nd\_day](https://avatars.discourse-cdn.com/v4/letter/2/a4c791/32.png) [@2nd\_day](https://forum.kirupa.com/u/2nd_day)\
**Post date:** [July 25, 2004, 6:29pm UTC](https://forum.kirupa.com/t/slowing-down/117186/3 "2004-07-25T18:29:29Z")

</div>

or maybe this will work:

```auto

on (press) {
	function go() {
		enemmyX = this._x;
		enemmyY = this._y;
		for (starX=_root.star1._x; starX>enemmyX; starX--) {
			_root.star1._x = _root.star1._x-1;
		}
	}
  theinterval = setInterval(go, 1000);
}

```

---

<div class="post-metadata">

**Author:** ![mad\_man](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mad\_man](https://forum.kirupa.com/u/mad_man)\
**Post date:** [July 25, 2004, 7:03pm UTC](https://forum.kirupa.com/t/slowing-down/117186/4 "2004-07-25T19:03:29Z")

</div>

umm this wut i have now but it just kinda like freezes then gives me a messege.

on (press) {  
enemmyX = this.\_x;  
enemmyY = this.\_y;

```
starY = _root.star1._y;
starX = _root.star1._x;

```

while(starX\>enemmyX || starY\>enemmyY){  
theinterval = setInterval(movestar, 1000);

}

```
function movestar(){
	if(starX&gt;enemmyX){
		_root.star1._x=_root.star1._x-1;	
		starX = _root.star1._x;
	}
	if(starY&gt;enemmyY){
		_root.star1._y=_root.star1._y-1;	
		starY = _root.star1._y;
	}
	clearInterval(theinterval);
}

```

}

---

<div class="post-metadata">

**Author:** ![2nd\_day](https://avatars.discourse-cdn.com/v4/letter/2/a4c791/32.png) [@2nd\_day](https://forum.kirupa.com/u/2nd_day)\
**Post date:** [July 25, 2004, 7:34pm UTC](https://forum.kirupa.com/t/slowing-down/117186/5 "2004-07-25T19:34:21Z")

</div>

could you explain what you want to happen when you click the button? because i don’t know why you want to use a interval, because the code will only be executed when the button is clicked… or maybe you can put the .fla online?

---

<div class="post-metadata">

**Author:** ![mad\_man](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mad\_man](https://forum.kirupa.com/u/mad_man)\
**Post date:** [July 25, 2004, 7:43pm UTC](https://forum.kirupa.com/t/slowing-down/117186/6 "2004-07-25T19:43:37Z")

</div>

ok i have a button inside a movie clip and thats wut this script is inside. and then i have a moveiclip called star. and when i pres this button i want the star to come to this objects coords but slowly and thats why i am using set interval.

---

<div class="post-metadata">

**Author:** ![2nd\_day](https://avatars.discourse-cdn.com/v4/letter/2/a4c791/32.png) [@2nd\_day](https://forum.kirupa.com/u/2nd_day)\
**Post date:** [July 25, 2004, 7:55pm UTC](https://forum.kirupa.com/t/slowing-down/117186/7 "2004-07-25T19:55:40Z")

</div>

so you want movieclip star to slowly move to the button? maybe this tutorial will help you [http://www.kirupa.com/developer/mx/ASmovement.htm](http://www.kirupa.com/developer/mx/ASmovement.htm)

---

<div class="post-metadata">

**Author:** ![mad\_man](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mad\_man](https://forum.kirupa.com/u/mad_man)\
**Post date:** [July 25, 2004, 8:14pm UTC](https://forum.kirupa.com/t/slowing-down/117186/8 "2004-07-25T20:14:11Z")

</div>

but thats only for entering the move i need on click.

---

<div class="post-metadata">

**Author:** ![2nd\_day](https://avatars.discourse-cdn.com/v4/letter/2/a4c791/32.png) [@2nd\_day](https://forum.kirupa.com/u/2nd_day)\
**Post date:** [July 25, 2004, 8:49pm UTC](https://forum.kirupa.com/t/slowing-down/117186/9 "2004-07-25T20:49:04Z")

</div>

try this code:

```auto

on(press){
	star.endx = this._x;
	star.endy = this._y;
	star.onEnterFrame = function(){
		speed = 10;
		x = this.endx - this._x;
		this._x += x/speed;
		y = this.endy - this._y;
		this._y += y/speed;
	}
}

```

if it doesn’t work: check if the path for star is correct… or put the fla online…

---

<div class="post-metadata">

**Author:** ![mad\_man](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@mad\_man](https://forum.kirupa.com/u/mad_man)\
**Post date:** [July 25, 2004, 9:08pm UTC](https://forum.kirupa.com/t/slowing-down/117186/10 "2004-07-25T21:08:42Z")

</div>

wow thanks alot man. Thank you

---

<div class="post-metadata">

**Author:** ![2nd\_day](https://avatars.discourse-cdn.com/v4/letter/2/a4c791/32.png) [@2nd\_day](https://forum.kirupa.com/u/2nd_day)\
**Post date:** [July 25, 2004, 9:33pm UTC](https://forum.kirupa.com/t/slowing-down/117186/11 "2004-07-25T21:33:22Z")

</div>

you’re welcome! i always like to help somebody 🙂
