# Button Effect

**URL:** <https://forum.kirupa.com/t/button-effect/13118>\
**Category:** flash\
**Created:** [February 9, 2003, 6:46am UTC](https://forum.kirupa.com/t/button-effect/13118 "2003-02-09T06:46:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlielha](https://avatars.discourse-cdn.com/v4/letter/c/3ab097/32.png) [@charlielha](https://forum.kirupa.com/u/charlielha)\
**Post date:** [February 9, 2003, 6:46am UTC](https://forum.kirupa.com/t/button-effect/13118/1 "2003-02-09T06:46:52Z")

</div>

Hello,

I am trying to make a rollover effect for a button. I have a word typed, the button, and I want to move this word around a certain area, randomly, when the user rolls over it.

Any idea on how this can be done??  
I am kind of blocked and haven’t figured it out

thanks

---

<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:** [February 9, 2003, 12:11pm UTC](https://forum.kirupa.com/t/button-effect/13118/2 "2003-02-09T12:11:32Z")

</div>

heres an idea, dunno if it works, or if it’ll even make sense though heh…

make a random number for x and for y

and say the random number for x and y are both 50

so then the word will go on coordinates (50,50)

---

<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:** [February 9, 2003, 2:22pm UTC](https://forum.kirupa.com/t/button-effect/13118/3 "2003-02-09T14:22:33Z")

</div>

in the overstate of your button make the content a movieclip  
then in the movie clip make your content move around by making animations…

you could probably do this in actionscrip, but if you’re novice as me it can be a bit hard

hope this helps!

---

<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:** [February 9, 2003, 3:45pm UTC](https://forum.kirupa.com/t/button-effect/13118/4 "2003-02-09T15:45:34Z")

</div>

i was bored so … i spent 5 - 10 minutes of my life in this

place the script in the timeline and remove all those [color=red]_[/color] in this line: button.wordBox.htmlText = "\<[color=red]_[/color]p align=‘center’\>\<[color=red]_[/color]font face=‘Verdana’ color=’#CCCCCC’\>kax\<[color=red]_[/color]/font\>\<[color=red]\*[/color]/p\>"

[size=1]

```auto
this.createEmptyMovieClip ("button", 0)

button.createEmptyMovieClip ("box", 0)
button.createTextField ("wordBox", 1, 0, 2, 40, 16)

button.box.moveTo (0, 0)
button.box.beginFill (0xFFFFFF, 100)
button.box.lineStyle (2, 0xCCCCCC, 100)
button.box.lineTo (40, 0)
button.box.lineTo (40, 20)
button.box.lineTo (0, 20)
button.box.lineTo (0, 0)
button.box.endFill ()

button.wordBox.html = true
button.wordBox.htmlText = "<*p align='center'><*font face='Verdana' color='#CCCCCC'>kax<*/font><*/p>"

button.onEnterFrame = function () {
	if (this.hitTest (this._parent._xmouse, this._parent._ymouse, true)) {
		if (!newPos) {
			newx = Math.round (- 20 + Math.random () * 40)
			newy = Math.round (- 20 + Math.random () * 40)
		}
		if (newx != this.wordBox._x || newy != this.wordBox._y) {
			if (newx < this.wordBox._x) {
				this.wordBox._x += Math.floor ((newx - this.wordBox._x) * .1)
			} else {
				this.wordBox._x += Math.ceil ((newx - this.wordBox._x) * .1)
			}
			if (newy < this.wordBox._y) {
				this.wordBox._y += Math.floor ((newy - this.wordBox._y) * .1)
			} else {
				this.wordBox._y += Math.ceil ((newy - this.wordBox._y) * .1)
			}
			newPos = true
		} else {
			newPos = false
		}
	} else {
		newPos = false
		newx = 0
		newy = 0
		if (newx != this.wordBox._x || newy != this.wordBox._y) {
			if (newx < this.wordBox._x) {
				this.wordBox._x += Math.floor ((newx - this.wordBox._x) * .1)
			} else {
				this.wordBox._x += Math.ceil ((newx - this.wordBox._x) * .1)
			}
			if (newy < this.wordBox._y) {
				this.wordBox._y += Math.floor ((newy - this.wordBox._y) * .1)
			} else {
				this.wordBox._y += Math.ceil ((newy - this.wordBox._y) * .1)
			}
		}
	}
}

```

[/size]  
if that’s what you want i’ll figure out an easier way 😉

[size=1]waiting for lostinbeta ilyaslamasse or senocular to belittle me :P[/size]
