# Moving a movie clip when a button is held down

**URL:** <https://forum.kirupa.com/t/moving-a-movie-clip-when-a-button-is-held-down/186066>\
**Category:** Uncategorized\
**Created:** [April 18, 2006, 7:57pm UTC](https://forum.kirupa.com/t/moving-a-movie-clip-when-a-button-is-held-down/186066 "2006-04-18T19:57:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ceejeeb](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@Ceejeeb](https://forum.kirupa.com/u/Ceejeeb)\
**Post date:** [April 18, 2006, 7:57pm UTC](https://forum.kirupa.com/t/moving-a-movie-clip-when-a-button-is-held-down/186066/1 "2006-04-18T19:57:40Z")

</div>

I have two buttons in my movie that move a movie clip up and down on my stage. the code in the buttons atm is as follows,

[FONT=Courier New]on ([COLOR=darkorchid]press[/COLOR]){  
[COLOR=darkorchid]if[/COLOR] ([COLOR=darkorchid]this[/COLOR].pics1.\_y\<-240) {  
} [COLOR=darkorchid]else[/COLOR] {  
[COLOR=darkorchid]this[/COLOR].pics1.\_y = ([COLOR=darkorchid]this[/COLOR].pics1.\_y-10);  
}[/FONT]

(this is just the down button)

This just checks to see if the movie clip has reached its lowest position and if it hasn’t it movies it down by 10px.

What i would like to do it make is so when the button is clicked and held the movie clip moves down untill the button is released.

How could i do this?  
(Im using Flash 8 with Actionscript 2)

---

<div class="post-metadata">

**Author:** ![MartinKool](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@MartinKool](https://forum.kirupa.com/u/MartinKool)\
**Post date:** [April 18, 2006, 8:38pm UTC](https://forum.kirupa.com/t/moving-a-movie-clip-when-a-button-is-held-down/186066/2 "2006-04-18T20:38:01Z")

</div>

First, remember that if you want the clip to move down, you have to increase the \_y, not decrease it.

What you’re missing, is time. I’ve attached an example using onEnterFrame. There are smarter ways to do this, but I think this is easiest to understand.

---

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [April 18, 2006, 11:33pm UTC](https://forum.kirupa.com/t/moving-a-movie-clip-when-a-button-is-held-down/186066/3 "2006-04-18T23:33:07Z")

</div>

or, name the two buttons  
up, and down

then

```auto

up.onPress=function () {
	moveIt(-5, 10);
}, down.onPress=function () {
	moveIt(5, 200);
};
function moveIt(dir, maxPoint) {
	pics1.onEnterFrame = function() {
		if ((dir<0 ? this._y>maxPoint : this._y<maxPoint)) {
			this._y += dir;
		}
	};
}
button.onReleaseOutside = button.onRelease=function () {
	delete _root.pics1.onEnterFrame;
};

```

:thumb:

---

<div class="post-metadata">

**Author:** ![Ceejeeb](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@Ceejeeb](https://forum.kirupa.com/u/Ceejeeb)\
**Post date:** [April 19, 2006, 1:17am UTC](https://forum.kirupa.com/t/moving-a-movie-clip-when-a-button-is-held-down/186066/4 "2006-04-19T01:17:57Z")

</div>

Thanks that did the job 😃
