I posted a thread and I’ve partly worked out how to do what I need but I still need a slight push in the right direction.

I’ve got two movieclips box and box2 and I’ve place them in the same layer because I couldn’t get each box to move individually in seperate ones I’ve placed this code on the frame

startx = box._x;
starty = box._y;
startx = box2._x;
starty = box2._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 dx = _xmouse-box2._x;
var dy = _ymouse-box2._y;
var distance = dxdx+dy*dy;
box.shakeYourBody(10000/(distance+1000));
box2.shakeYourBody(10000/(distance+1000));
};

Now I’ve got both movieclips shaking but they’re on top of each other rather than in the places I want them. I’m sure its a case of changing something but what?

It’s the first four lines! You are assiging the value of box._x to startx and the box._y to starty and then you are assining them again but foer the other box!
Just make it
startx = box._x
starty = box._y
startx2 = box2._x
startx2 = box2._y

but there’s something strange going on there! hwo can you place that first code on a frame if there are lines which start with “this.”.
there shoud be scripts on both of the boxes… :-\

Nope, the problem is that you overwrite dx and dy.

this.onEnterFrame = function() {
// Find distance
var dx = _xmouse-box._x;
var dy = _ymouse-box._y;
var distance = dx*dx+dy*dy;
box.shakeYourBody(10000/(distance+1000));
var dx = _xmouse-box2._x;
var dy = _ymouse-box2._y;
var distance = dx*dx+dy*dy;
box.shakeYourBody(10000/(distance+1000));
box2.shakeYourBody(10000/(distance+1000));
};

I’ve changed the script to this as ilyaslamasse posted but the two boxs are still on top of each other when I publish the movie…even thought they are on the other side of the screen to eachother.

startx = box._x;
starty = box._y;
startx = box2._x;
starty = box2._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 = dxdx+dydy;
box.shakeYourBody(10000/(distance+1000));
var dx = _xmouse-box2._x;
var dy = _ymouse-box2._y;
var distance = dxdx+dy*dy;
box2.shakeYourBody(10000/(distance+1000));
};
:-\