在 Actionscript 3.0 中使用 pinchzoom 控制时间线

Control timeline with pinchzoom in Actionscript 3.0

我在 Flash 中使用 Actionscript 3.0。有没有办法通过捏合来控制时间线(所以不是缩放 out/in,而是移动时间线 back/forth)?我正在开发一个故事应用程序,玩家可以控制故事。

您可以执行以下操作:

import flash.events.TransformGestureEvent;
Multitouch.inputMode = MultitouchInputMode.GESTURE;

stop();

//listen on whatever object you want to be able zoom on
stage.addEventListener(TransformGestureEvent.GESTURE_ZOOM , zoomGestureHandler); 

function zoomGestureHandler(e:TransformGestureEvent):void{
    //get the zoom amount (since the last event fired)
    //we average the two dimensions (x/y). 1 would mean no change,  .5 would be half the size as before, 2 would twice the size etc.
    var scaleAmount:Number = (e.scaleX + e.scaleY) * 0.5;

    //set the value (how many frames) to skip ahead/back
    //we want the value to be at least 1, so we use Math.max - which returns whichever value is hight
    //we need a whole number, so we use Math.round to round the value of scaleAmount
    //I'm multiplying scaleAmount by 1.25 to make the output potentially go a bit higher, tweak that until you get a good feel.
    var val:int = Math.max(1, Math.round(scaleAmount * 1.25));

    //determine if the zoom is actually backwards (smaller than before)
    if(scaleAmount < 1){
        val *= -1;  //times the value by -1 to make it a negative number
    }

    //now assign val to the actual target frame
    val = this.currentFrame + val;

    //check if the target frame is out of range (less than 0 or more than the total)
    if(val < 1) val = this.totalFrames + val; //if less than one, add (the negative number) to the totalFrames value to loop backwards
    if(val > this.totalFrames) val = val - this.totalFrames; //if more than total, loop back to the start by the difference

    //OR
    if(val < 1) val = 0; //hard stop at the first frame (don't loop)
    if(val > this.totalFrames) val = this.totalFrames; //hard stop at the last frame (don't loop)

    //now move the playhead to the desired frame
    gotoAndStop(val);
}