Keep Larger Image or Object draggable within stage - Actionscript


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

This function will keep an image that is larger than the stage dragging within the stage view, stopping at any edge of the image.


Copy this code and paste it in your HTML
  1. hiResSprite.addEventListener(MouseEvent.MOUSE_DOWN,startDragHiRes);
  2.  
  3. function startDragHiRes(e:Event):void {
  4. var hiResWidth = e.target.width;
  5. var hiResHeight = e.target.height;
  6. var stageWidthVal = stage.stageWidth;
  7. var stageHeightVal = stage.stageHeight;
  8.  
  9. var hiResX = hiResWidth - stageWidthVal;
  10. var hiResY = hiResHeight - stageHeightVal;
  11. var dragWidth = hiResWidth - stageWidthVal;
  12. var dragHeight = hiResHeight - stageHeightVal;
  13.  
  14. var hiResDragRect = new Rectangle(-hiResX,-hiResY,dragWidth,dragHeight);
  15. hiResSprite.startDrag(false,hiResDragRect);
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.