繁体   English   中英

使用AS3放大和缩小

[英]Zoom in and zoom out using AS3

你们都知道:“右键单击 - >放大或缩小”在flash文件中,好吧,我需要这样做但是使用,例如,单击按钮。

这只能使用AS3代码吗?

谢谢!

你必须将所有图形放在一个精灵中,例如“场景”,然后修改它的比例......

实际上,如果你想缩放/缩放/缩小舞台或视频对象或其他任何东西,应该使用乘法和除法。 像这样(这是我在需要为网络摄像头创建缩放/缩放功能时使用的 - 当然使用缩放功能进行数字缩放):

假使,假设:


video_width = 640;
video_height = 480;

stage.scaleMode     = StageScaleMode.NO_SCALE; 
stage.align         = StageAlign.TOP_LEFT;
stage.stageWidth    = video_width;
stage.stageHeight   = video_height;


camera = Camera.getCamera();
// some other params

video = new Video( video_width, video_height );
video.attachCamera(camera);
addChild(video);

// to mirror webcam output:
video.scaleX = -1;
video.scaleY = 1;
video.x = video_width;
video.y = 0;


public function zoom(action:String = 'reset')
{
      var step = 1.1, // adjust this multiplyer for faster zoom. Eg. 1.2, 1.5, etc.
          x_offset = 0, 
          y_offset = 0;

    if (action == 'in')
    {
        video.scaleX *= step;
        video.scaleY *= step;

        x_offset = (stage.stageWidth - video.width)/2;
        y_offset = (stage.stageHeight - video.height)/2;
                // to center video object on stage by X if mirror effect is used
        video.x = stage.stageWidth - x_offset; 
                // to center video object on stage by X - no mirror
                // video.x = x_offset;
        video.y = y_offset; // to center video object on stage by Y
    }
    else if (action == 'out')
    {
            video.scaleX /= step;
        video.scaleY /= step;

        x_offset = (stage.stageWidth - video.width)/2;
        y_offset = (stage.stageHeight - video.height)/2;
        video.x = stage.stageWidth - x_offset;
        video.y = y_offset;
    }
    else
    {
                // need to be mirrored
        video.scaleX = -1; 
                // no mirror
                 // video.scaleX = 1;
        video.scaleY = 1;
                // if mirror video output
        video.x = stage.stageWidth;
               // no mirroring used
               // video.x = 0;
        video.y = 0;
    }       
}

现在通过将此功能附加到按钮来使用它:


zoom('in');
zoom('out'); 
zoom('reset'); // reset zoom

不是我所知道的。 很想看到其他答案。

想到的一个hacky事情是,也许你可以使用javascript来控制包含你的swf的div,以便div变大(放大),但是显示在同一个'scrollRect'矩形内。 你可以调用javascript函数来使用ExternalInterface来做到这一点。

我使用flash的scrollPane组件做了一个快速的测试:

//zoomIn,zoomOut = button
//sp = scrollPane, scrollDrag = true
zoomIn.addEventListener(MouseEvent.CLICK, zoom);
zoomOut.addEventListener(MouseEvent.CLICK, zoom);

function zoom(event:MouseEvent) {
    var scale:Number = event.currentTarget == zoomIn ? 1 : -1;
    sp.content.scaleX += scale;
    sp.content.scaleY += scale;
    sp.update();
}

然后我注意到你正在使用flex,所以肯定必须有一个允许你具有类似功能的容器。

HTH,乔治

我也会使用scaleX和scaleY,但只是使用数字而不是George的解决方案和var。 所以,像

zoomInButton.addEventListener(MouseEvent.MOUSE_DOWN, zoomIn);
zoomOutButton.addEventListener(MouseEvent.MOUSE_DOWN, zoomOut);

function zoomIn(e:MouseEvent) {
  //actions for zoom-in function
  myPicture.scaleX += 10;
  myPicture.scaleY += 10;
}
function zoomOut(e:MouseEvent) {
  //actions for zoom-out function
  myPicture.scaleX += 10;
  myPicture.scaleY += 10;
}

你可能会偶然发现另一个障碍,即图片从左上角缩放到左上角。 在这种情况下,尝试使用缩放移动图片。 喜欢

function zoomIn(e:MouseEvent) {
  //actions for zoom-in function
  myPicture.scaleX += 10;
  myPicture.scaleY += 10;
  myPicture.x -= 5;
  myPicture.y -= 5;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM