I have 5 movieclips placed on the stage, all in the same spot. I’m trying to make this hittest code have them all bump off eachother - so they never touch. when you click an object + drag it, I want it to push the other clips away.
It halfway works… but only certain clips push others away. It seems like clips higher in the index don’t get pushed away by lower ones, or visa-versa.
How can I get around that? Whatever clip is selected needs to always push the others away.
Here’s the code.
import caurina.transitions.Tweener;
var i:int = 0;
var j:int = 0;
function bumper(e:Event) {
for (i=0; i<numChildren; i++) {
for (j=i+1; j<numChildren; j++) {
if (getChildAt(j).hitTestObject(getChildAt(i))) {
Tweener.addTween(getChildAt(i), {x:Math.random()*stage.stageWidth, y:Math.random()*stage.stageHeight, time:1, transition:"easeOutElastic"});
}
}
}
}
stage.addEventListener(Event.ENTER_FRAME, bumper);
for (i=0; i<numChildren; i++) {
getChildAt(i).addEventListener(MouseEvent.CLICK, dr);
}
function dr(e) {
e.currentTarget.startDrag();
}