Advertisement
Guest User

Untitled

a guest
Oct 14th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // listen to when the mouse is pressed
  2. addEventListener(MouseEvent.MOUSE_DOWN,downHandler);
  3.  
  4. funciton downHandler(e:MouseEvent):void{
  5. // listen to when the mouse is released
  6. stage.addEventListener(MouseEvent.MOUSE_UP,upHandler);
  7. // listen to when the mouse is moved
  8. stage.addEventListener(MouseEvent.MOUSE_MOVE,draw);
  9. // set a random color and line width from 1 to 5
  10. graphics.lineStyle(Math.random()*0xFFFFFF,Math.floor(Math.random()*5)+1);
  11. // move line  to starting point of mouse
  12. graphics.moveTo(e.stageX,e.stageY);
  13. }
  14. function draw(e:MouseEvent):void{
  15.  
  16. // draw line
  17. graphics.lineTo(e.stageX,e.stageY);
  18. }
  19. function upHandler(e:MouseEvent):void{
  20. stage.removeEventListener(MouseEvent.MOUSE_UP,upHandler);
  21. stage.removeEventListener(MouseEvent.MOUSE_MOVE,draw);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement