如何在AS2中获取已加载的swf载物台的宽度/高度? [英] How can I get the width/height of a loaded swf's stage in AS2?

查看:116
本文介绍了如何在AS2中获取已加载的swf载物台的宽度/高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MovieClipLoader将外部as2 swf文件加载到我的as2 flash项目中,但是我无法获取已加载swf的原始舞台大小。

I'm using MovieClipLoader to load an external as2 swf file into my as2 flash project, and I'm having trouble getting the original stage size of the loaded swf.

当我运行以下代码时:

var popup:MovieClip = _root.createEmptyMovieClip("popup", 1);
var loader:MovieClipLoader = new MovieClipLoader();
var loadHandler:Object = new Object();
loader.addListener(loadHandler);
loader.loadClip(url, popup); 
loadHandler.onLoadInit = function(mc:MovieClip) {
    trace(mc._width + ", " + mc._height);
}

我得到奇怪的宽度/高度值(mc._width = 601.95,mc。 _height = 261.15),当我真正想要的是加载的swf文件的阶段大小时,在这种情况下,我知道该大小为300px x 250px。

I get strange width/height values (mc._width=601.95, mc._height=261.15) when what I actually want is the stage size of the loaded swf file, which in this case I know to be 300px x 250px.

任何建议都值得赞赏!
谢谢

Any suggestions appreciated! Thanks

推荐答案

此处的问题是,加载的SWF文件在加载到另一个SWF文件中时会失去其舞台大小。父级变成加载swf的阶段。如您所要求的那样,当请求加载的swf的大小时,它将返回第一帧的整个表面的宽度和高度,而不是舞台的宽度和高度。

The problem here is that the loaded swf looses it's stage size when it's loaded into another swf. The stage of the parent becomes the stage of loaded swf. When requesting the size of the loaded swf, like you do, it will return the width and height of the entire surface of the first frame, not that of the stage.

我过去解决此问题的方法是在加载的SWF文件的第一帧上以该SWF文件的舞台大小创建一个movieclip实例。载入瑞士法郎后,您可以定位该瑞士法郎并获取其尺寸。当然,仅当您对要加载的swf拥有​​发布控制权时,此方法才有效。

The way I've solved this in the past is to create a movieclip instance on the first frame of the loaded swf with the size of the stage of that swf. Once the swf has been loaded you can then target that swf and get it's dimensions. Of course, this only works if you have publishing control over the swf you're trying to load.

在一个示例中进行说明。在要加载的瑞士法郎中,将动画片段(例如矩形的动画片段)放在第一帧上,并将其命名为stage_mc。现在,当您加载swf时,可以像这样定位target_mc实例:

To illustrate this in an example. In your swf to be loaded place a movieclip (e.g. a movieclip of a rectangle) on the first frame and name it stage_mc. When you now load the swf you can target that stage_mc instance like so:

loadHandler.onLoadInit = function(mc:MovieClip) {
    trace(mc.stage_mc._width + ", " + mc.stage_mc._height);
}

这篇关于如何在AS2中获取已加载的swf载物台的宽度/高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆