ActionScript rotated sprite's startDrag bounds
- by TheDarkIn1978
when assigning a bounds to a draggable sprite, it doesn't seem to take rotation of the sprite into consideration.
the code below adds a sprite to the display list, rotates it 45º, and adds a MouseEvent.MOUSE_DOWN event to allow dragging.
the startDrag() method's second parameter simply returns the bounds of the stage as a rectangle. however, because of the sprite's rotation, its corners can be dragged past the bounds of the stage.
any thoughts?
var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0x0000FF, 1);
mySprite.graphics.drawRect(0, 0, 200, 200);
mySprite.graphics.endFill();
mySprite.rotation = 45;
addChild(mySprite);
mySprite.addEventListener(MouseEvent.MOUSE_DOWN, dragSprite, false, 0, true);
function dragSprite(evt:MouseEvent):void
{
evt.target.startDrag(false, spriteBounds());
}