# Button

**URL:** <https://forum.kirupa.com/t/button/592>\
**Category:** flash\
**Created:** [July 23, 2002, 4:02pm UTC](https://forum.kirupa.com/t/button/592 "2002-07-23T16:02:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phreak](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@Phreak](https://forum.kirupa.com/u/Phreak)\
**Post date:** [July 23, 2002, 4:02pm UTC](https://forum.kirupa.com/t/button/592/1 "2002-07-23T16:02:53Z")

</div>

hi, on [http://www.pankpages.com/mainsite.htm](http://www.pankpages.com/mainsite.htm), how would you get the arrow to go over the button when your mouse is over the button?

---

<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 23, 2002, 7:47pm UTC](https://forum.kirupa.com/t/button/592/2 "2002-07-23T19:47:06Z")

</div>

Im a bit tight for time, but this should get you started

build arrow  
make arrow MC

the trick is that when your \_xmouse,\_ymouse comes within range of the buttons (using hittest, for example), the arrow mc \_x will be equal to the \_xmouse.

That is the crude version and it will just snap to the \_xmouse (pretty much)…

to make it ease into it would require a bit more time…

hope it helped a little

---

<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 23, 2002, 8:01pm UTC](https://forum.kirupa.com/t/button/592/3 "2002-07-23T20:01:13Z")

</div>

## OOPS! Didn’t notice that is followed the mouse! Well montoya explained a bit of the techinques I explained the smoothment thingy! The hittest tutorial is loacted here: [http://www.kirupa.com/developer/actionscript/hittest.asp](http://www.kirupa.com/developer/actionscript/hittest.asp) =)

I’m on a non-flashed computer right now but I hope this works… 🙂  
Make a button! Make sure the centerpoint of the button is at the center of the button! (not in the corner or…)  
Now make the arrow and place it where you want it to be if the mouse is not over some of the buttons!  
Right-click the button and choose Actions!  
Copy-paste the code given:

```auto
 on (rollOver) {
_root.btn1over = true;
}
on (rollOut) {
_root.btn1over = false;
}

```

## That just makes a value of a variable become true when you roll over the button and it also makes it become false when you roll out. note: It’s good to store all the variables to “\_root” for easier navigation.

Now right-click the arrow and choose Actions!  
now copy-paste the code given:

```auto
onClipEvent(load) {
_root.xpos = this._x;
}
onClipEvent(enterFrame) {
if (_root.btn1over) {
this._x += ( **btnxpos** -this._x)/3;
} else {
this._x += (_root.xpos-this._x)/3
}
}

```

NB! Change “btnxpos” to the \_x position of the button!  
There ya have it!  
For multipile buttons you have t change the “btn1over” varfiable for every button (btn1over, btn2over, btn3over)  
And that else thingy won’t work either!  
You have to add

```auto
 _root.arrowpos = false; 

```

in the rollOver handler  
and

```auto
 _root.arrowpos = true;

```

in the rollOut handler  
so it would be:

```auto
 on (rollOver) {
_root.btn1over = true;
_root.arrowpos = false;
}
on (rollOut) {
_root.btn1over = false;
_root.arrowpos = true;
}

```

and change the actioscript on the arrow to:

```auto
onClipEvent(load) {
_root.xpos = this._x;
}
onClipEvent(enterFrame) {
if (_root.btn1over) {
this._x += ( **btnxpos** -this._x)/ **3** ;
}
if(_root.arrowpos) {
this._x += (_root.xpos-this._x)/ **3**
}
}

```

you also have to change “btnxpos” for every button!  
Oh Yeah I almost forgot! You can change the “3” in the end of the 2 lines! The higher the number the slower and smoother the movement will be!  
note: every variable can be changed to whatever you like. But it has to be changed to the same thing in the places where it is used or the script won’t work!  
Well… I hope that Helped!  
=)

---

<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 23, 2002, 8:08pm UTC](https://forum.kirupa.com/t/button/592/4 "2002-07-23T20:08:25Z")

</div>

Thanks Skyo and Iammontoya

---

<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 23, 2002, 8:25pm UTC](https://forum.kirupa.com/t/button/592/5 "2002-07-23T20:25:52Z")

</div>

with that code, you dont need mine at all.

We should start populating the Best of Kirupa with stuff like this… probably should clean it up just a bit…

---

<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 24, 2002, 5:19am UTC](https://forum.kirupa.com/t/button/592/6 "2002-07-24T05:19:54Z")

</div>

And make an example fla…  
By the way, did anyone try Syko’s code ?

pom :asian:
