Skip to main content
Participant
Aug 8, 2013 8:02 AM UTC
Question

Zoom in/out

Hello, I have to do an imagen zoom in/out by a double tap in as3 for android. I have resolve the zoom in and a pan:

map_mc.addEventListener(MouseEvent.DOUBLE_CLICK, fl_MouseDoubleClickHandler);

function fl_MouseDoubleClickHandler(event:MouseEvent):void

{

    map_mc.scaleX *= 2;

    map_mc.scaleY *= 2;

}

/* Evento de toque y arrastre

Permite mover el objeto sujetando y arrastrando el objeto.

*/

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

map_mc.addEventListener(TouchEvent.TOUCH_BEGIN, fl_TouchBeginHandler);

map_mc.addEventListener(TouchEvent.TOUCH_END, fl_TouchEndHandler);

var fl_DragBounds:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);

function fl_TouchBeginHandler(event:TouchEvent):void

{

    event.target.startTouchDrag(event.touchPointID, false, fl_DragBounds);

}

if(event.phase==fl_TouchBeginHandler.BEGIN){

map_mc.removeEventListener(MouseEvent.DOUBLE_CLICK, fl_MouseDoubleClickHandler);

}

function fl_TouchEndHandler(event:TouchEvent):void

{

    event.target.stopTouchDrag(event.touchPointID);

}

map mc is the image.

How can I do the zoom out by another double tap?

Thank you

This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

Participant
Aug 8, 2013 11:23 AM UTC

Ohhh great!!! Thank you

Translate
Mark.fromOP
Inspiring
Aug 9, 2013 3:24 AM UTC

Please mark it as correct if it was correct. You are welcome!

Translate
Mark.fromOP
Inspiring
Aug 8, 2013 10:21 AM UTC

You just need a variable that keeps track of you being zoomed or not.

Create a variable like zoomedInOnImage

var zoomedInOnImage:Boolean = false;

//set up variables to keep track of initial map x and y and scale

var mapInitialWidth = map_mc.width;

var mapInitialHeight = map_mc.height;

var mapInitialX = map_mc.x;

var mapInitialY = map_mc.y;

map_mc.addEventListener(MouseEvent.DOUBLE_CLICK, fl_MouseDoubleClickHandler);

function fl_MouseDoubleClickHandler(event:MouseEvent):void

{

     if (zoomedInOnImage == false)

     {

         map_mc.width = mapInitialWidth * 2;

         map_mc.height = mapInitialHeight * 2;

         zoomedInOnImage = true;

     }

     else if (zoomedInOnImage == true)

     {

         map_mc.width = mapInitialWidth;

         map_mc.height = mapInitialHeight;

         map_mc.x= mapInitialX;

         map_mc.y= mapInitialY;

         zoomedInOnImage = false;

     }

}

Translate