Posted By

GunnarHKarlsson on 11/11/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

captiv8tor


zoom for android


 / Published in: ActionScript 3
 

  1. view.addListener(TransformGestureEvent.GESTURE_ZOOM, onZoom);
  2.  
  3. private function onZoom(e:TransformGestureEvent):void {
  4. var bounds1:Rectangle = view.content.getBounds(view.stage);
  5.  
  6. // scale the view
  7. view.scaleX *= e.scaleX;
  8. view.scaleY *= e.scaleY;
  9.  
  10. var bounds2:Rectangle = view.content.getBounds(view.stage);
  11. var dx:Number = bounds2.x - bounds1.x;
  12. var dy:Number = bounds2.y - bounds1.y;
  13. var dw:Number = bounds2.width - bounds1.width;
  14. var dh:Number = bounds2.height - bounds1.height;
  15.  
  16. // move the view to keep it centered while zooming
  17. view.x -= dx + dw/2;
  18. view.y -= dy + dh/2;
  19. }

Report this snippet  

You need to login to post a comment.