Drawing Application


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package {
  2. import flash.display.Sprite;
  3. import flash.events.MouseEvent;
  4.  
  5. public class ExampleApplication extends Sprite{
  6. private var _sprite:Sprite;
  7.  
  8. public function ExampleApplication(){
  9. _sprite = new Sprite();
  10. addChild(_sprite);
  11. _sprite.graphics.beginFill(0xFFFFFF);
  12. _sprite.graphics.drawRect(0, 0, 400, 400);
  13. _sprite.graphics.endFill();
  14.  
  15. _sprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
  16. _sprite.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
  17.  
  18. }
  19. private function onMouseDown(event:MouseEvent):void{
  20. _sprite.graphics.lineStyle(1, 0, 1);
  21. _sprite.graphics.moveTo(mouseX, mouseY);
  22. _sprite.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
  23. }
  24. private function onMouseUp(event:MouseEvent):void{
  25. _sprite.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
  26. }
  27. private function onMouseMove(event:MouseEvent):void{
  28. _sprite.graphics.lineTo(mouseX, mouseY);
  29. }
  30. }
  31. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.