# Rollover vibration effect help!

**URL:** <https://forum.kirupa.com/t/rollover-vibration-effect-help/184434>\
**Category:** flash\
**Created:** [April 5, 2006, 4:10am UTC](https://forum.kirupa.com/t/rollover-vibration-effect-help/184434 "2006-04-05T04:10:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukebattye](https://avatars.discourse-cdn.com/v4/letter/l/9d8465/32.png) [@lukebattye](https://forum.kirupa.com/u/lukebattye)\
**Post date:** [April 5, 2006, 4:10am UTC](https://forum.kirupa.com/t/rollover-vibration-effect-help/184434/1 "2006-04-05T04:10:15Z")

</div>

Hi there,

I’ve been using flash for about a week now and have been sifting through online tutorials to get me up to speed and I’m really loving it.

As a noob to action script iv kind of jit a brick wall. Theres a tutorial on the site for making something vibrate, say a button, but i want to initiate this effect when someone rolls over it. I have the code for the vibration and iv looked up the code for rollover but i cant seem to get them to work with each other.

Here’s the code for the vibrating effect…

onClipEvent (load) {  
//movie width/height  
height = 200;  
width = 300;  
//------------------------//  
//makes everything random //  
//------------------------//  
this.\_x = Math.round(Math.random()\*width);  
this.\_y = Math.round(Math.random()\*height);  
var temp = this.\_alpha=Math.random()\*100;  
this.\_xscale = this.\_yscale=temp;  
//setting initiaion position  
cx = this.\_x;  
cy = this.\_y;  
}  
onClipEvent (enterFrame) {  
//causes the object to be offset  
this.\_x = cx+(1+Math.random()\*5);  
this.\_y = cy+(1+Math.random()\*5);  
}

Any help would be amazing 🙂

Thanks for your time :thumb2:

Luke

---

<div class="post-metadata">

**Author:** ![kenvunz](https://avatars.discourse-cdn.com/v4/letter/k/c5a1d2/32.png) [@kenvunz](https://forum.kirupa.com/u/kenvunz)\
**Post date:** [April 5, 2006, 11:13am UTC](https://forum.kirupa.com/t/rollover-vibration-effect-help/184434/2 "2006-04-05T11:13:05Z")

</div>

```auto
 
//movie width/height
height = 200;
width = 300;
//------------------------//
//makes everything random //
//------------------------//
with(mc) {
    _x = Math.round(Math.random()*width);
    _y = Math.round(Math.random()*height);
    _xscale = _yscale= _alpha = Math.random()*100;
    //setting initiaion position
    cx = _x;
    cy = _y;
}
mc.onRollOver = function() {
    mc.onEnterFrame = function() {
        //causes the object to be offset
    this._x = cx+(1+Math.random()*5);
    this._y = cy+(1+Math.random()*5);
    }
}

```

Assuming that your MovieClip instance that you want it to be vibrated is _mc_.

---

<div class="post-metadata">

**Author:** ![lukebattye](https://avatars.discourse-cdn.com/v4/letter/l/9d8465/32.png) [@lukebattye](https://forum.kirupa.com/u/lukebattye)\
**Post date:** [April 6, 2006, 2:30pm UTC](https://forum.kirupa.com/t/rollover-vibration-effect-help/184434/3 "2006-04-06T14:30:59Z")

</div>

> [@kenvunz](#):
>
> ```auto
>  
> //movie width/height
> height = 200;
> width = 300;
> //------------------------//
> //makes everything random //
> //------------------------//
> with(mc) {
> _x = Math.round(Math.random()*width);
> _y = Math.round(Math.random()*height);
> _xscale = _yscale= _alpha = Math.random()*100;
> //setting initiaion position
> cx = _x;
> cy = _y;
> }
> mc.onRollOver = function() {
> mc.onEnterFrame = function() {
> //causes the object to be offset
> this._x = cx+(1+Math.random()*5);
> this._y = cy+(1+Math.random()*5);
> }
> }
> 
> ```
> 
> Assuming that your MovieClip instance that you want it to be vibrated is _mc_.

Hi there, thanks for getting back to e, sorry its taken a couple of days to reply iv had connections issues. I tried doing it and made the button a movie clip with an instance name mc but i get this…

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: Statement must appear within on/onClipEvent handler  
height = 200;  
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: Statement must appear within on/onClipEvent handler  
width = 300;  
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 7: Statement must appear within on/onClipEvent handler  
with(mc) {  
**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 15: Statement must appear within on/onClipEvent handler  
mc.onRollOver = function() {  
Total ActionScript Errors: 4 Reported Errors: 4

Any ideas?

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 6, 2006, 2:37pm UTC](https://forum.kirupa.com/t/rollover-vibration-effect-help/184434/4 "2006-04-06T14:37:27Z")

</div>

you cannot use the above code on a button, it would go in the main movie.

---

<div class="post-metadata">

**Author:** ![lukebattye](https://avatars.discourse-cdn.com/v4/letter/l/9d8465/32.png) [@lukebattye](https://forum.kirupa.com/u/lukebattye)\
**Post date:** [April 7, 2006, 5:15am UTC](https://forum.kirupa.com/t/rollover-vibration-effect-help/184434/5 "2006-04-07T05:15:23Z")

</div>

I’ve tried converting the button to a movie clip and then putting in a na actions layer with the code. I also tried putting the code onto the actual movie itself but it either tells me that the instance doesn’t exist (i’ve made sure the instance name is mc so it should right?) or it looks really small. either way the effect doesnt seem to work. Im sure this is really simple to you guys so i appologise for being stupid with this but any more pointers would be really appreciated.

Thanks so much for your time 🙂

---

<div class="post-metadata">

**Author:** ![Pascal\_S](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Pascal\_S](https://forum.kirupa.com/u/Pascal_S)\
**Post date:** [April 7, 2006, 6:22am UTC](https://forum.kirupa.com/t/rollover-vibration-effect-help/184434/6 "2006-04-07T06:22:21Z")

</div>

i put the code in a fla for you maybe this wil help you understand

(the file is mx2004 but you can open it in 8)
