Actionscript 3.0 编程实例二 鼠标事件 (写给初学的朋友)
代码直接可以运行 liveTea
package
{
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
//[SWF(width="800", heigth="400",backgroudColor="#ffffff",frameRate="31")]
public class AS3Test extends Sprite
{
private var _sprite:Sprite=new Sprite();
public function AS3Test()
{
//23
graphics.lineStyle(1, 16711935, 1);
trace("aaa");
//showMessage("aaa");
/* for(var i:int=0;i<200;i++)
{
graphics.lineTo(Math.random()*200,Math.random()*300)
} */
// addEventListener(Event.ENTER_FRAME,aa);
_sprite.graphics.beginFill(16711935, 1);
_sprite.graphics.drawCircle(150, 150, 100);
_sprite.graphics.endFill();
addChild(_sprite);
_sprite.addEventListener(MouseEvent.MOUSE_OVER, mouse_over);
_sprite.addEventListener(MouseEvent.CLICK, mouse_click);
stage.focus=this;
addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
}
private function keyDown(event:KeyboardEvent):void
{
trace("jjj");
}
/* private function aa(event:Event):void{
//graphics.lineTo(Math.random()*400,Math.random()*600)
} */
private function mouse_click(event:MouseEvent):void
{
_sprite.graphics.moveTo(mouseX, mouseY);
_sprite.graphics.lineStyle(1, 16711935, 1);
_sprite.graphics.lineTo(Math.random() * 400, Math.random() * 600);
}
private function mouse_over(event:MouseEvent):void
{
_sprite.graphics.moveTo(10, 10);
_sprite.graphics.lineStyle(1, 16711935, 1);
_sprite.graphics.lineTo(Math.random() * 400, Math.random() * 600);
}
}
}