package ... { /**//** * 采用事件相应实现的简单画图程序 * * */ import flash.display.Sprite; import flash.display.StageScaleMode; import flash.display.StageAlign; import flash.events.MouseEvent; import flash.events.KeyboardEvent; import flash.text.TextField; import flash.system.System; import flash.system.Capabilities; import flash.net.FileReference; public class ASProject extends Sprite ...{ private var _sprite:Sprite; public function ASProject() ...{ Initialize(); showInfo(); stage.scaleMode=StageScaleMode.NO_SCALE; stage.align=StageAlign.TOP_RIGHT; stage.showDefaultContextMenu=false; graphics.beginFill(0xffffff); graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight); graphics.endFill(); /**//*浏览本地文件*/ var fileReference:FileReference=new FileReference(); fileReference.browse(); } public function showInfo():void ...{ /**//*显示本地系统信息*/ var txt:TextField=new TextField(); var osInfo:String="OS:"+Capabilities.os; txt.text=osInfo; addChild(txt); txt.appendText(" Version:"+Capabilities.version+" Language:"+Capabilities.language +" Manufacturer:"+Capabilities.manufacturer); } public function Initialize():void ...{ stage.focus=this; addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown); _sprite=new Sprite(); addChild(_sprite); } public function Draw():void ...{ _sprite.graphics.beginFill(0xffffff); _sprite.graphics.drawRect(0,0,400,400); _sprite.graphics.endFill(); _sprite.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown); _sprite.addEventListener(MouseEvent.MOUSE_UP,onMouseUp); } /**//* private function onEnterFrame(event:Event):void { graphics.lineTo(Math.random()*400,Math.random()*400); } */ private function onKeyDown(event:KeyboardEvent):void ...{ trace("Key down:"+event.charCode); } 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 onMouseMove(event:MouseEvent):void ...{ _sprite.graphics.lineTo(mouseX,mouseY); } private function onMouseUp(event:MouseEvent):void ...{ _sprite.removeEventListener(MouseEvent.MOUSE_MOVE,onMouseMove); } }}