Apache flex 使用AS3进行放大和缩小

Apache flex 使用AS3进行放大和缩小,apache-flex,actionscript-3,zooming,out,Apache Flex,Actionscript 3,Zooming,Out,你们都知道:“右键点击->放大或缩小”在flash文件中,嗯,我需要这样做,但使用,例如,点击一个按钮 这是否可能仅使用AS3代码 谢谢 据我所知不是这样。但我很想看到其他答案 我想到的一件棘手的事情是,也许你可以使用javascript 要控制包含swf的div,使div变大(放大), 但显示在同一个“scrollRect”矩形内。你会打电话给 javascript函数使用ExternalInterface来实现这一点 我使用flash的滚动窗格组件做了一个快速的“脏”测试: //zoomIn

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

这是否可能仅使用AS3代码


谢谢

据我所知不是这样。但我很想看到其他答案

我想到的一件棘手的事情是,也许你可以使用javascript 要控制包含swf的div,使div变大(放大), 但显示在同一个“scrollRect”矩形内。你会打电话给 javascript函数使用ExternalInterface来实现这一点

我使用flash的滚动窗格组件做了一个快速的“脏”测试:

//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,所以肯定有一个容器允许您使用类似的功能

嗯,,
George

您必须将所有图形放在一个精灵中,例如“场景”,然后修改其比例…

我也会使用scaleX和scaleY,但只是使用一个数字,而不是George的带有变量的解决方案

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;
}

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

假设:


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

是 啊在Flex中有效,但。。。我仍然没有使用本机闪光灯变焦。我想知道是否有办法使用它,目前我将使用这个解决方案,thx。