//生成的_sprite里进行鼠标绘画
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
//设置舞台的尺寸,帧频
//[SWF(width = "500", height = "400", backgroundColor = "0xd4ded4", frameRate = "24")]
public class Main extends Sprite
{
private var _sprite:Sprite;
public function Main()
{
_sprite = new Sprite();
addChild(_sprite);
_sprite.graphics.beginFill(0xc7edcc);
_sprite.graphics.drawRect(50, 50, 450, 450);
_sprite.graphics.endFill();
_sprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
_sprite.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
}
private function onMouseDown(event:MouseEvent):void
{
_sprite.graphics.lineStyle(1, 0, 1);
_sprite.graphics.moveTo(mouseX, mouseY);
_sprite.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseUp(event:MouseEvent):void
{
_sprite.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
private function onMouseMove(event:MouseEvent):void
{
_sprite.graphics.lineTo(mouseX, mouseY);
}
}
}
page 12 MouseEvent
最新推荐文章于 2024-08-15 15:51:51 发布