I want to have a square on my web page which is static until the mouse gets closer. as the mouse gets to a certain distance the box begins to shake, then shakes less when the mouse gets further away.
Does anyone know how to achieve this???
cheers
You mean some kind of proximity detector? Yeah, I’m sure that’s possible. You’d have to monitor the _x and _y properies of the cursor, then compare it to those of your box MC… As the number start to get coser together, you shake the box… I’d need a little time to work it out scripting-wise, but I’m sure a genuis like Ilyas could figure out the code.
thad would be a need tutorial:q:
Oh, yeah
Mebbe I’ll try and make something similar… not a tut, just trying it…
If you have a clip called box on the scene, you can try that kind of code:
startx=box._x;
starty=box._y;
MovieClip.prototype.shakeYourBody=function(radius){
forceX=2*(Math.random()-.5)*radius;
forceY=2*(Math.random()-.5)*radius;
this._x=startx+forceX;
this._y=starty+forceY;
}
this.onEnterFrame=function(){
// Find distance
var dx=_xmouse-box._x;
var dy=_ymouse-box._y;
var distance=dx*dx+dy*dy;
box.shakeYourBody(100000/(distance+10));
}
I don’t have time to explain right now, sorry :-\
pom :crazy:
cheeeeeers everyone for the interest…thanks for the code aswell!!
postatomic
Ok…
I’ve tried more than one box (infact three) and named them all different and changed the code to match each clip but only the first one works…if I delete the first one then the rest work?? strange…work that one out…hehe