Skip to main content
Participant
August 8, 2013
Question

Zoom in/out

  • August 8, 2013
  • 3 replies
  • 578 views

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 has been closed for replies.

3 replies

Participant
August 8, 2013

Ohhh great!!! Thank you

Mark.fromOP
Inspiring
August 9, 2013

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

Mark.fromOP
Inspiring
August 8, 2013

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;

     }

}