Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. var bounds:Rectangle = new Rectangle(rect.width/2-img.width/2, rect.height/2-img.height/2, rect.width-img.width, rect.height-img.height);
  2.  
  3. img.addEventListener(MouseEvent.MOUSE_DOWN, drag);
  4. img.addEventListener(MouseEvent.MOUSE_UP, drop);
  5.  
  6. function drag(event:MouseEvent) {
  7. img.startDrag(false, bounds);
  8. }
  9. function drop(event:MouseEvent) {
  10. img.stopDrag();
  11. }
  12.  
  13. var bounds:Rectangle = new Rectangle();
  14. bounds.x = rect.x + (img.width * .5) - (rect.width * .5); //offset by + half of the image, and - half of the rectangle
  15. bounds.y = rect.y + (img.height * .5) - (rect.height * .5);
  16. bounds.width = rect.width - img.width; //make the bounds the size of the rectangle, minus the size of the image
  17. bounds.height = rect.height - img.height;
  18.  
  19. new Rectangle(0,0,100,100)
  20.  
  21. boundingBox.graphics.moveTo(0,0);
  22. boundingBox.graphics.beginFill(0);
  23. boundingBox.graphics.lineTo(400,0);
  24. boundingBox.graphics.lineTo(400,400);
  25. boundingBox.graphics.lineTo(0,400);
  26. boundingBox.graphics.lineTo(0,0);
  27. boundingBox.graphics.endFill();
  28. boundingBox.x = 100;
  29. boundingBox.y = 100;
  30.  
  31.  
  32. dragTarget.graphics.moveTo(0,0);
  33. dragTarget.graphics.beginFill(0xff0000);
  34. dragTarget.graphics.drawRect(0,0,10,10);
  35. dragTarget.graphics.endFill();
  36. dragTarget.x = 150;
  37. dragTarget.y = 150;
  38.  
  39. container.addChild(boundingBox)
  40. container.addChild(dragTarget)
  41. this.addChild(container)
  42.  
  43. dragTarget.addEventListener(MouseEvent.MOUSE_DOWN,onDown)
  44.  
  45.  
  46. var boundingBox:Sprite = new Sprite();
  47. var dragTarget:Sprite = new Sprite();
  48. var container:Sprite = new Sprite()
  49. function onDown(event:Event):void{
  50. var bounds:Rectangle = new Rectangle(boundingBox.x,
  51. boundingBox.y,
  52. boundingBox.width-dragTarget.width,
  53. boundingBox.height-dragTarget.height)
  54. dragTarget.startDrag( false,bounds )
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement