2
votes

I'm having problems finding the exact answer I'm looking for. I'm building an application that currently allows pinch zooming on an image. This is being built in Flash Builder 4.5. What I want specifically is to keep the image the same dimensions while zooming in and out. So the image still increases and decreases but stays within an invisible box.

Does that explanation make sense?

Right now I can zoom in and out but it changes the image size and covers the other content. Eventually other features will be added including pan and rotate. The image will become a 3D model of a mouth.

If tutorials or sources are supplied that would be great.

Here's my code for the zoom gesture which is using the TransformGestureEvent:

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.TransformGestureEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;

private function init():void
{
    img.addEventListener(TransformGestureEvent.GESTURE_ZOOM, onZoom);
}

private function onZoom(event:TransformGestureEvent):void
{
    var mySprite:Sprite = img as Sprite;
    if(mySprite.scaleY.valueOf() >= 1)
    {
        mySprite.scaleX *= event.scaleX;
        mySprite.scaleY *= event.scaleY;
    }
    else
    {
        mySprite.scaleX= 1;
        mySprite.scaleY = 1;
    }
}
1

1 Answers

0
votes

If i understand you question correctly. I think you may want to look at scrollRect http://gskinner.com/blog/archives/2006/11/understanding_d.html

DisplayObject.scrollRect lets you specify a Rectangle object that defines the region of the DisplayObject (Sprite, MovieClip, etc) to display. The masked region is always displayed at the origin of the display object, which lets you scroll the region by changing the x and y properties of the rectangle.