Hi Friends,
I made a class for moving MovieClip randomly, its working fine…
But I have some problem…
-
MovieClips named “ball” are overlapping with each other. when they hits, the “ball” direction should be change, which I want.
-
I have define a moving area as stage.width and stage.height,
the target file is ‘ground.fla’ I have a another movieclip named “areaMc”, I want to define moving area with areaMc, How can I do.?
my code is: -
this code is in “Comman_ball.as”
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.text.*;
public class Comman_ball extends MovieClip {
private var speedX:Number = Math.random()*2-1;
private var speedY:Number = Math.random()*2-1;
private var speedR:Number = Math.random()*10-5;
private var sizeX:Number = Math.random()*30+20;
private var sizeY:Number = Math.random()*30+20;
function Comman_ball ():void {
this.addEventListener (Event.ENTER_FRAME, moveSprite);
}
private function moveSprite (evt:Event):void {
evt.target.ranNumber.text = Math.round(Math.random()*100);
evt.target.x += speedX;
evt.target.y += speedY;
//evt.target.rotation += speedR;
if (evt.target.x > stage.stageWidth || evt.target.x < 0) {
speedX = -speedX;
speedR = -speedR;
}
if (evt.target.y > stage.stageHeight || evt.target.y < 120) {
speedY = -speedY;
//speedR = -speedR;
}
/*if (evt.target.hitTestObject(evt.target.hitMc))
{
speedY = -speedY;
trace("hitting")
}*/
}
}
}