PDA

View Full Version : why do the 2 puppets have not independent movement ?



aneuryzma
June 29th, 2009, 04:05 AM
hi,

I don't understand why the movements of the second puppet are summed to the movements of the first one.

See this: http://dl.getdropbox.com/u/72686/lancelmaat2.html

In other words, I would like the puppets to be completely independent from each other.

thanks


public function lancelmaat() {





for (var i:int = 0; i < 2; i++) {

herms[i] = new Herm();



addChild(herms[i]);


herms[i].x=stage.stageWidth/4;
herms[i].y=i*100+30;



herms[i].addEventListener(MouseEvent.MOUSE_OVER,onMouseOve r);


}


}








private function onMouseOver(event:MouseEvent):void {

var sign = 1;
//if (Math.random() > 0.5) sign = sign*-1;
ax = sign * (Math.random() / 2);
ay = sign * (Math.random() / 4);
vx = 0;
vy = 0;

event.target.removeEventListener(MouseEvent.MOUSE_ OVER,onMouseOver);
event.target.addEventListener(Event.ENTER_FRAME,on Movement);

}



private function onMovement(event:Event):void {


vx += ax;
vy += ay;


event.target.y += vy;
event.target.x += vx;


...
}

aneuryzma
June 29th, 2009, 04:42 AM
I've solved.

I was using a variable in common.