Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // listen to when the mouse is pressed
- addEventListener(MouseEvent.MOUSE_DOWN,downHandler);
- funciton downHandler(e:MouseEvent):void{
- // listen to when the mouse is released
- stage.addEventListener(MouseEvent.MOUSE_UP,upHandler);
- // listen to when the mouse is moved
- stage.addEventListener(MouseEvent.MOUSE_MOVE,draw);
- // set a random color and line width from 1 to 5
- graphics.lineStyle(Math.random()*0xFFFFFF,Math.floor(Math.random()*5)+1);
- // move line to starting point of mouse
- graphics.moveTo(e.stageX,e.stageY);
- }
- function draw(e:MouseEvent):void{
- // draw line
- graphics.lineTo(e.stageX,e.stageY);
- }
- function upHandler(e:MouseEvent):void{
- stage.removeEventListener(MouseEvent.MOUSE_UP,upHandler);
- stage.removeEventListener(MouseEvent.MOUSE_MOVE,draw);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement