有人可以向我解释为什么此 ActionScript 代码的行为是自动缩放吗?

发布于 2024-10-29 22:23:18 字数 1026 浏览 1 评论 0原文

我是 AS3 的新手,正在为 AIR 做一些自定义视频播放器视频项目。当我研究有关如何播放视频的简单示例(非 StageVideo)时,我遇到了一种独特的情况,我从 Flash 获得了非常棒的自动缩放(拉伸以适合)窗口行为。

每当我将 SWF 指令的宽度和高度设置为等于我正在创建的 flash.media.Video 对象的宽度和高度时。它执行自动缩放、拉伸以适合、调整大小的行为。就像这样:

// SWF directive placed before the class declaration of the main class
[SWF( width="1024", height="576", backgroundColor="000000", visible="true" )]

// somewhere in my initialization
myvid = new Video();
with( myvid )
{
    x = 0;
    y = 0;
    width = 1024; // if I set this wxh equal to wxh in the SWF directive it auto-scales!
    height = 576;
}
myvid.attachNetStream( myns );
addChild( myvid ); // must come after instancing of video and netstream, and attach to make the auto-scale work
myvid.play( "somevideo.flv" );

即使我将宽度设置为 16,高度设置为 9,它也会缩放并完美适合我的窗口大小。 有人可以解释一下我的这种行为吗?我在文档中读到的内容都没有提到这一点。

不要误会我的意思,我喜欢这种行为! :) 这让我的事情变得更容易。但就代码而言,我需要理解为什么会发生这种情况,因为我设置的代码与自动缩放无关。

另外,指令到底有什么用?他们不是只有纯 ActionScript 3 等效项吗?在我看来,它们看起来很黑客。

I'm new to AS3 and I'm doing some custom video player video project for AIR. While I was studying the simple examples (non-StageVideo) on how to play videos, I've encountered a unique situation where I got an awesome auto-scaling (stretch-to-fit) to window behavior from Flash.

Whenever I set the SWF directive's width and height equal to the width and height of the flash.media.Video object I'm creating. It does the auto-scaling, stretch-to-fit, resizable behavior. Like so:

// SWF directive placed before the class declaration of the main class
[SWF( width="1024", height="576", backgroundColor="000000", visible="true" )]

// somewhere in my initialization
myvid = new Video();
with( myvid )
{
    x = 0;
    y = 0;
    width = 1024; // if I set this wxh equal to wxh in the SWF directive it auto-scales!
    height = 576;
}
myvid.attachNetStream( myns );
addChild( myvid ); // must come after instancing of video and netstream, and attach to make the auto-scale work
myvid.play( "somevideo.flv" );

Even if I set the width to 16 and height to 9 on both it scales and fits perfectly on the size of my window. Can some explain me this behavior? None of what I read in the documentation mentioned this.

Don't get me wrong, I like this behavior! :) It made things easier for me. But code-wise I need to understand why is this happening as the code I set had nothing to do with auto-scaling.

Also, what the heck are directives for? Don't they just have pure ActionScript 3 equivalent? They look hackish to me.

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

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

发布评论

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

评论(1

请帮我爱他 2024-11-05 22:23:18

我认为您所描述的行为是由 Flash 的 HTML 嵌入中的 scale 参数引起的。通常,默认为 showAll,放大 Flash 以适应容器。

有两种不同的大小:容器的大小(HTML 页面中的块)和 Flash 内容的大小(您在 SWF 标记中指定的内容)。缩放模式决定这些尺寸不匹配时的行为。您可以通过调整嵌入参数来控制此行为,也可以直接从 AS3 使用 stage.scaleMode

import flash.display.StageScaleMode;
// scale the content to fit the container, maintaing aspect ratio
stage.scaleMode = StageScaleMode.SHOW_ALL;
// disable scaling
stage.scaleMode = StageScaleMode.NO_SCALE;

如果您想使用缩放模式来发挥自己的优势,我会设置视频的宽度以匹配舞台尺寸,如下所示

myvid.width = stage.stageWidth;
myvid.height = stage.stageHeight;

:这样您就不必重复 SWF 宽度和高度。

这些指令主要为编译器指定一些元数据或指令。 SWF 标签特别指定 SWF 标头中的信息,例如所需的宽度、高度、帧速率。大多数情况下,这些只是向播放器+容器提供有关如何显示文件的一些建议。其中一些可以在代码中更改 (stage.frameRate = 50;)。另一个元标记是 Embed,它将把一些资源捆绑到 SWF 中(如果您想嵌入一些二进制数据,则特别方便)。

I think the behavior you're describing is caused by the scale parameter in the HTML embed of the Flash. Generally this defaults to showAll, scaling the Flash up to fit the container.

There are two different sizes: the size of the container (the block in the HTML page) and the size of the Flash content (what you specify in the SWF tag). The scale mode decides the behavior when these sizes don't match. You can control this behavior either by tweaking that embed parameter, or from AS3 directly using stage.scaleMode:

import flash.display.StageScaleMode;
// scale the content to fit the container, maintaing aspect ratio
stage.scaleMode = StageScaleMode.SHOW_ALL;
// disable scaling
stage.scaleMode = StageScaleMode.NO_SCALE;

If you want to use the scale mode to your advantage, I would set the width of your Video to match the stage dimensions like so:

myvid.width = stage.stageWidth;
myvid.height = stage.stageHeight;

This way you avoid having to repeat the SWF width and height.

The directives mostly specify some metadata or instructions for the compiler. The SWF tag in particular specifies the info in the SWF header, such as desired width, height, framerate. Mostly these are just some suggestions to the player + container about how the file should be displayed. Some of them can be changed in code (stage.frameRate = 50;). Another metatag is Embed, which will bundle some assets into the SWF (particularly handy if you want to embed some binary data).

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