从“主”访问阶段班级
我有以下 ActionScript:
package {
import flash.display.Sprite;
public class Application extends Sprite {
public function Application(){
width=1000;
height=500;
}
}
}
我使用 mxmlc Application.as
进行编译。我注意到应用程序并不是舞台对象,就像我想象的那样,因为舞台的宽度和高度没有改变。
如何从Application
访问舞台?
I have the following ActionScript:
package {
import flash.display.Sprite;
public class Application extends Sprite {
public function Application(){
width=1000;
height=500;
}
}
}
Which I compile with mxmlc Application.as
. What I have noticed is that Application is not the stage object, like I thought it would be, because the width and height of the stage are not changing.
How do you access the stage from Application
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您巧妙地误解了“舞台”的含义。舞台是 Flash 必须使用的显示区域的最低级别引用,因此其大小最终由 Flash 正在其中执行的容器决定。
因此,当您在独立 Flash 播放器中查看内容时,要调整舞台大小,您需要调整播放器本身的大小,并且当您查看嵌入在 HTML 页面中的内容时,只有当浏览器更改嵌入 Flash 的元素的大小(例如通过 Javascript)时,舞台才会调整大小。同样,如果您的闪存嵌入到 .NET 应用程序中,则 .NET 逻辑可以控制舞台的大小,等等。
由于这些原因,通常不可能从应用程序逻辑内调整阶段的大小,除非容器公开了一种方法来执行此操作。大多数浏览器确实通过 JavaScript 公开了此类功能,因此在浏览器中,您通常可以通过调用 JS 挂钩来更改 Flash 嵌入元素的大小来调整舞台大小。相比之下,独立播放器没有公开这样的挂钩,因此无法调整舞台大小(当然,您可以切换全屏)。
作为旁注,正如 Joel Hooks 指出的那样,您可以在项目中包含以下形式的语句:
[SWF(width=1000,height=500)]
。这会导致编译后的 SWF 包含指定大小的元数据。然而,该元数据只是一个建议,是否遵守它完全取决于容器。独立播放器将尊重此类元数据(对于初始容器大小),但浏览器将完全忽略它。You're subtly misunderstanding what "Stage" refers to. The stage is the lowest-level reference to the display area Flash has to work with, so its size is ultimately dictated by the container Flash is executing in.
Thus when you view your content in the standalone Flash player, to resize the stage you resize the player itself, and when you view your content embedded in an HTML page, the stage only resizes when the browser changes the size of the element Flash is embedded into (via Javascript, for instance). Likewise if your flash was embedded into a .NET application, the .NET logic has control over the size of the stage, and so on.
For these reasons, it is not generally possible to resize the stage from within application logic, unless the container exposes a way to do it. Most browsers do indeed expose such functionality via JavaScript, so in a browser you can normally resize the stage by calling JS hooks to change the size of Flash's embed element. In contrast the standalone player exposes no such hooks, so resizing the stage is impossible (except of course that you can toggle fullscreen).
As a side note, as Joel Hooks points out, you can include a statement in your project of the form:
[SWF(width=1000,height=500)]
. This causes the compiled SWF to contain metadata for the stated size. That metadata is only a suggestion, however, and it's entirely up to the container whether to honor it or not. The standalone player will honor such metadata (for the initial container size), but browsers will ignore it entirely.