Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- img.addEventListener(MouseEvent.MOUSE_DOWN, drag);
- img.addEventListener(MouseEvent.MOUSE_UP, drop);
- function drag(event:MouseEvent) {
- img.startDrag(false, bounds);
- }
- function drop(event:MouseEvent) {
- img.stopDrag();
- }
- var bounds:Rectangle = new Rectangle();
- bounds.x = rect.x + (img.width * .5) - (rect.width * .5); //offset by + half of the image, and - half of the rectangle
- bounds.y = rect.y + (img.height * .5) - (rect.height * .5);
- bounds.width = rect.width - img.width; //make the bounds the size of the rectangle, minus the size of the image
- bounds.height = rect.height - img.height;
- new Rectangle(0,0,100,100)
- boundingBox.graphics.moveTo(0,0);
- boundingBox.graphics.beginFill(0);
- boundingBox.graphics.lineTo(400,0);
- boundingBox.graphics.lineTo(400,400);
- boundingBox.graphics.lineTo(0,400);
- boundingBox.graphics.lineTo(0,0);
- boundingBox.graphics.endFill();
- boundingBox.x = 100;
- boundingBox.y = 100;
- dragTarget.graphics.moveTo(0,0);
- dragTarget.graphics.beginFill(0xff0000);
- dragTarget.graphics.drawRect(0,0,10,10);
- dragTarget.graphics.endFill();
- dragTarget.x = 150;
- dragTarget.y = 150;
- container.addChild(boundingBox)
- container.addChild(dragTarget)
- this.addChild(container)
- dragTarget.addEventListener(MouseEvent.MOUSE_DOWN,onDown)
- var boundingBox:Sprite = new Sprite();
- var dragTarget:Sprite = new Sprite();
- var container:Sprite = new Sprite()
- function onDown(event:Event):void{
- var bounds:Rectangle = new Rectangle(boundingBox.x,
- boundingBox.y,
- boundingBox.width-dragTarget.width,
- boundingBox.height-dragTarget.height)
- dragTarget.startDrag( false,bounds )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement