使用 AS3 放大和缩小

发布于 2024-08-28 05:32:03 字数 100 浏览 6 评论 0原文

你们都知道:在 Flash 文件中“右键单击 -> 放大或缩小”,好吧,我需要执行此操作,但使用例如单击按钮。

仅使用 AS3 代码可以吗?

谢谢!

you all know: "right click -> zoom in or out" in flash file, well, I need to do this but using, for example, clicking a button.

Is this possible using only AS3 code?

Thx!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

终止放荡 2024-09-04 05:32:03

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

you must put all your graphics in a sprite, for example "scene" and then modify its scale...

ぃ双果 2024-09-04 05:32:03

据我所知还没有。不过很想看到其他答案。

我想到的一件棘手的事情是,也许你可以使用 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,所以肯定有一个容器可以让你实现类似的功能。

哈特哈,
乔治

Not as far as I know. Curious to see other answers though.

One hacky thing that comes to mind is, maybe you could use javascript
to control a div containing your swf so that the div gets large(zoom in),
but is displayed within the same 'scrollRect' rectangle. you would call the
javascript function to do that using ExternalInterface.

A quick'n'dirty test I did using flash's scrollPane component:

//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();
}

Then I've noticed you are using flex, so surely there must be a a container that will allow you a similar functionality.

HTH,
George

万水千山粽是情ミ 2024-09-04 05:32:03

我也会使用scaleX和scaleY,但只是用一个数字而不是乔治的带有var的解决方案。因此,像 You 这样的东西

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

I would use scaleX and scaleY also, but simply with a number instead of George's solution with a var. So, something like

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

You might stumble upon another obstacle though, which is that the picture gets scaled from and to the upper left corner. In that case try moving the picture with the scaling. Like

function zoomIn(e:MouseEvent) {
  //actions for zoom-in function
  myPicture.scaleX += 10;
  myPicture.scaleY += 10;
  myPicture.x -= 5;
  myPicture.y -= 5;
}
难理解 2024-09-04 05:32:03

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

假设:


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

Actually if you want to scale/zoomin/zoomout a stage or video object or anything else, multiply and divide should be used instead. Like this (this is what I used when I needed to create zoomin/zoomout functionality for web camera - digital zoom of course using scale functionality):

Assume that:


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

Now you use this by attaching this functions to your buttons:


zoom('in');
zoom('out'); 
zoom('reset'); // reset zoom
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文