Monday, April 04, 2011

Flex Mobile Development - Transform Gestures

The example code below provides a quick look at how to register an event handler for TransformGestureEvent.TRANSFORM_ZOOM.

Line 11 adds the event listener to the BorderContainer (line 41).  The Transform event is passed to the onZoom function on line 14, which has a member variable of type Sprite.  By reading the scale of the event's scaleY property, you can enforce a minimum size as shown by the if-else statement on lines 17-26 and assign the new values.  Note that the minimum scale size this can go to is 1.  This is to prevent users from scaling the Sprite too small to place both fingers on it to zoom again.

The code may be downloaded from here.  You will need Flash Builder 4 and AIR 2.5 or later to run this.


  1. Hi Duane Chaos,
    I watched your video of Transform Gestures. Really helpful. What I need additionally is, how to retain the previous zoom position or the parent zoom position?

    What I want to achieve is, I have a map image wherein the user can zoom in or zoom out. For eg, if the user zooms in Delhi, he needs to see the large image of Delhi after the zoom. But in your case, the image always stays at the same place.

    I really got stuck in this. Could you please help me out to solve this issue? This could be really a minor issue but I am really missing something...

  2. The previous and current zoom positions can be read and stored as values before the transform event. In the transform handler function, add something like
    startX = (referenceToUIComponent).x and read the size.

    For what you want, there is an application using PixelBender that you might want to copy. Is this sort of close to what you want?



Do not spam this blog! Google and Yahoo DO NOT follow comment links for SEO. If you post an unrelated link advertising a company or service, you will be reported immediately for spam and your link deleted within 30 minutes. If you want to sponsor a post, please let us know by reaching out to duane dot nickull at gmail dot com.