Adobe Animate CC

Flash AS3 pinch and zoom [EN]

For a project i’m working on i needed a pinch and zoom function, the project is for use on a tablet. After many hours of using google i found different scripts and together they made the solution to my problem! It’s not only that it had to zoom in and out, but it had to have a minimum and maximum zoom range. So, here is the complete sollution for this nifty interaction:

Multitouch.inputMode = MultitouchInputMode.GESTURE;
 
McName.addEventListener(TransformGestureEvent.GESTURE_ZOOM , onZoom);
var MIN_ZOOM:Number = 0.8;//minimal zoom percentage 80%
var MAX_ZOOM:Number = 2;//maximal zoom percentage 200%
 
function onZoom(e:TransformGestureEvent):void{
	McName.scaleX *=  e.scaleX;
	McName.scaleY *=  e.scaleY;
	McName.scaleX = Math.max(MIN_ZOOM,McName.scaleX);
	McName.scaleY = Math.max(MIN_ZOOM,McName.scaleY);
	McName.scaleX = Math.min(MAX_ZOOM,McName.scaleX);
	McName.scaleY = Math.min(MAX_ZOOM,McName.scaleY);
}

Geef een reactie