# Move a button with your mouse, help!

**URL:** <https://forum.kirupa.com/t/move-a-button-with-your-mouse-help/58942>\
**Category:** flash\
**Created:** [July 27, 2004, 8:22am UTC](https://forum.kirupa.com/t/move-a-button-with-your-mouse-help/58942 "2004-07-27T08:22:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonsebergsen](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@simonsebergsen](https://forum.kirupa.com/u/simonsebergsen)\
**Post date:** [July 27, 2004, 8:22am UTC](https://forum.kirupa.com/t/move-a-button-with-your-mouse-help/58942/1 "2004-07-27T08:22:29Z")

</div>

[http://www.intentionallies.co.jp/content\_normal.html](http://www.intentionallies.co.jp/content_normal.html)

I know this site is very complex.But just the moving around buttons feature.  
Got any AS for this?

Lets say i have a square that i can move aorund on the screen with my mouse. And when its pressed it opens a .swf

Great forum :to:

---

<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 27, 2004, 8:42am UTC](https://forum.kirupa.com/t/move-a-button-with-your-mouse-help/58942/2 "2004-07-27T08:42:09Z")

</div>

look up startDrag() and stopDrag(). You can do a search for something like this in kirupa’s forums. Most questions have already been asked once if not twice.

---

<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 27, 2004, 10:00am UTC](https://forum.kirupa.com/t/move-a-button-with-your-mouse-help/58942/3 "2004-07-27T10:00:23Z")

</div>

> [@bobdoe](#):
>
> look up startDrag() and stopDrag(). You can do a search for something like this in kirupa’s forums. Most questions have already been asked once if not twice.

I did that sounds great.  
But is it possible to add a AS that makes the MC turn and float like  
on the web page i referred to?

simon :bu:

---

<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 27, 2004, 10:20am UTC](https://forum.kirupa.com/t/move-a-button-with-your-mouse-help/58942/4 "2004-07-27T10:20:30Z")

</div>

yeah, that’s possible, just add it in the on(press) event (where the startDrag is located).

---

<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 27, 2004, 10:30am UTC](https://forum.kirupa.com/t/move-a-button-with-your-mouse-help/58942/5 "2004-07-27T10:30:39Z")

</div>

btw, here is some sample code:

[AS]  
on (press) {  
startDrag(this);  
this.onMouseMove = function() {  
this.\_rotation = this.\_rotation + .5;  
}  
}  
[/AS]

Just put it on the movieClip you wish to drag and rotate. You can change it, so it turn in different directions depending on which direction you move…

---

<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 27, 2004, 3:11pm UTC](https://forum.kirupa.com/t/move-a-button-with-your-mouse-help/58942/6 "2004-07-27T15:11:26Z")

</div>

[QUOTE=sintax]btw, here is some sample code:

[AS]  
on (press) {  
startDrag(this);  
this.onMouseMove = function() {  
this.\_rotation = this.\_rotation + .5;  
}  
}

How will the script look i want on(release) to just slowly move by it self until stop. Like on the wab page i showed you.  
[http://www.intentionallies.co.jp/content\_normal.html](http://www.intentionallies.co.jp/content_normal.html)

And is it possible to not just make it rotate one way. But rotate in a simlilar way as web page above.

Im probably asking to much :sailor:  
yupp

---

<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 27, 2004, 3:28pm UTC](https://forum.kirupa.com/t/move-a-button-with-your-mouse-help/58942/7 "2004-07-27T15:28:54Z")

</div>

I experimented a bit this afternoon, cuz i kinda expected you would ask this 😉

[AS]  
on (press) {  
startDrag(this);  
this.onMouseMove = function() {  
var mousePos:Number = this.\_xmouse;  
this.onEnterFrame = function() {  
if (this.\_xmouse \> mousePos) {  
this.\_rotation = this.\_rotation + 1;  
} else {  
this.\_rotation = this.\_rotation - 1;  
}  
}  
}  
}

on (release) {  
stopDrag();  
delete this.onMouseMove;  
delete this.onEnterFrame;  
}

on (releaseOutside) {  
stopDrag();  
delete this.onMouseMove;  
delete this.onEnterFrame;  
}  
[/AS]

With this code the movieClip moves in two ways, depending on the direction of your mouse. I know this code isn’t perfect, and it needs some modifications to make it more usable, but it’s a good starting point I guess… The rest is up to you (or someone else :))

The effect your after (the fading out movement) is a bit to hard for me to do right now (busy doing other projects), but I guess it has got something to do with easing. Read some excellent tutorials on:  
[http://www.bit-101.com/tutorials/](http://www.bit-101.com/tutorials/)

Anyway, I hope was of some assistance 😉
