ActionScript 3 Start and Stop Drag


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

simple example of startDrag and stopDrag using AS3


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.