在 Flash 手势中缩放调整大小

Zoom resize in Flash Gesture

我对缩放有限制,因此您可以将缩放比例从 100% 调整到 150%。但是,我进行缩放,然后平移到缩放后 MC 的右上角,然后当我缩小时,MC 停留在左侧,MC 从屏幕上消失。看不到MC了

如何在不使用 Stage 的情况下缩小 MC?这是我的缩放代码:

function onZoom(e:TransformGestureEvent):void {

    var MIN_ZOOM:Number = 1; //minimal zoom percentage 100%
    var MAX_ZOOM:Number = 1.5; //maximal zoom percentage 150%

    escenario.scaleX *= e.scaleX;
    escenario.scaleY *= e.scaleY;
    escenario.scaleX = Math.max(MIN_ZOOM, escenario.scaleX);
    escenario.scaleY = Math.max(MIN_ZOOM, escenario.scaleY);
    escenario.scaleX = Math.min(MAX_ZOOM, escenario.scaleX);
    escenario.scaleY = Math.min(MAX_ZOOM, escenario.scaleY);

}

这是双指缩放手势。

您还需要检查 xy 属性。如果 MovieClip 的位置超出 Stage 范围,则需要更正它们。

If you are working with Classes and the MAX_ZOOM and MIN_ZOOM are constants, is recommendable to declare them like they are. This code assumes that you have your MovieClip in the root, you want to maintain it inside the Stage bounds and the MovieClip with scale of 1 have the same size as the Stage, change the code depending of your layout.

private const MIN_ZOOM:Number = 1;
private const MAX_ZOOM:Number = 1.5;

private function onZoom(e:TransformGestureEvent):void {

    var scale:Number = Math.min(e.scaleX, e.scaleY);

    escenario.scaleX *= scale;

    // Check if the scale is between the min and max parameters
    if(escenario.scaleX > MAX_ZOOM) escenario.scaleX = MAX_ZOOM;
    if(escenario.scaleX < MIN_ZOOM) escenario.scaleX = MIN_ZOOM;

    escenario.scaleY = escenario.scaleX;

    // Check is the MovieClip is inside the Stage bounds
    if(escenario.x > 0) escenario.x = 0;
    if(escenario.y > 0) escenario.y = 0;
    if(escenario.x + escenario.width < escenario.stage.stageWidth) escenario.x = escenario.stage.stageWidth - escenario.width;
    if(escenario.y + escenario.height < escenario.stage.stageHeight) escenario.y = escenario.stage.stageHeight - escenario.height;

}