Divar Yab
Divar Yab

Reputation: 127

AS3 - detect Zoom In from Zoom Out in GESTURE_ZOOM

I need to find a way to simply distinguish if the user has Zoomed IN or Zommed OUT, in AS3.

It is not about scaling up or down a picture. I want to let user Zoom in on a text to make it larger (FontSize++) or Zoom out on it to make it smaller (FontSize--).

myTextBox.addEventListener(TransformGestureEvent.GESTURE_ZOOM , onZoom);
function onZoom(e:TransformGestureEvent):void {
    //if it is zoom in => call fontSizeInc  
    //if it is zoom out => call fontSizeDec
}

Kind Regards, Ali

Upvotes: 0

Views: 79

Answers (1)

Divar Yab
Divar Yab

Reputation: 127

I found the answer by creating an experimental application and Try and Error.

To inform users that may have similar questions in the future, when we pinch the screen, in order to determine whether the zoom is going inward or outward, to execute a function based on that, we may use scaleX or scaleY, and seem there is no difference between these 2 in this case!

As a result:

  • If e.scaleX or e.scaleY was greater than 1, that is, zoom in.
  • If e.scaleX or e.scaleY was smaller than 1, that is, zoom out.

Here is the code:

myTextBox.addEventListener(TransformGestureEvent.GESTURE_ZOOM , onZoom);
function onZoom(e:TransformGestureEvent):void {
 if (e.scaleX > 1) {
  fontSizeInc();
 } else if (e.scaleX < 1) {
  fontSizeDec();    
 }
}

Thanks

Upvotes: 2

Related Questions