Posted By

CammoKing on 02/11/11


Tagged

actionscript as3flash


Versions (?)

Keep Larger Image or Object draggable within stage - Actionscript


 / Published in: ActionScript 3
 

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

  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  

You need to login to post a comment.