package{
import flash.display.Sprite;
import flash.events.Event;
public class mouse extends Sprite{
private var ball:Sprite;
public function mouse(){
ball = Ball();
addChild(ball);
ball.x = 50;
ball.y = 50;
ball.addEventListener(Event.ENTER_FRAME,moveball);
}
private function Ball():Sprite{
var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xffff00);
sp.graphics.drawCircle(0,0,10);
sp.graphics.endFill();
return sp;
}
//定义事件
private function moveball(evt:Event):void{
var dx:Number = mouseX - ball.x;
var dy:Number = mouseY - ball.y;
var vx:Number = dx/2;
var vy:Number = dy/2;
ball.x += vx;
ball.y += vy;
}
}
}
import flash.display.Sprite;
import flash.events.Event;
public class mouse extends Sprite{
private var ball:Sprite;
public function mouse(){
ball = Ball();
addChild(ball);
ball.x = 50;
ball.y = 50;
ball.addEventListener(Event.ENTER_FRAME,moveball);
}
private function Ball():Sprite{
var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xffff00);
sp.graphics.drawCircle(0,0,10);
sp.graphics.endFill();
return sp;
}
//定义事件
private function moveball(evt:Event):void{
var dx:Number = mouseX - ball.x;
var dy:Number = mouseY - ball.y;
var vx:Number = dx/2;
var vy:Number = dy/2;
ball.x += vx;
ball.y += vy;
}
}
}