如何获取 AS2 中加载的 swf 舞台的宽度/高度?

发布于 2024-07-23 02:01:16 字数 583 浏览 5 评论 0原文

我正在使用 MovieClipLoader 将外部 as2 swf 文件加载到我的 as2 flash 项目中,但在获取加载的 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文件的阶段大小,在这种情况下我知道是300 像素 x 250 像素。

任何建议表示赞赏! 谢谢

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.

When I run the following code:

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

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

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

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

发布评论

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

评论(3

请远离我 2024-07-30 02:01:16

这里的问题是,当加载的 swf 加载到另一个 swf 中时,它的舞台大小会丢失。 父级的阶段成为加载的 swf 的阶段。 当请求加载的 swf 的大小时,就像您所做的那样,它将返回第一帧整个表面的宽度和高度,而不是舞台的宽度和高度。

我过去解决这个问题的方法是在加载的 swf 的第一帧上创建一个影片剪辑实例,其大小与该 swf 的舞台大小相同。 加载 swf 后,您就可以定位该 swf 并获取其尺寸。 当然,只有当您对要加载的 swf 具有发布控制权时,这才有效。

通过一个例子来说明这一点。 在要加载的 swf 中,将一个影片剪辑(例如,矩形的影片剪辑)放在第一帧上,并将其命名为 stage_mc。 现在加载 swf 时,您可以像这样定位 stage_mc 实例:

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

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.

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.

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);
}
心意如水 2024-07-30 02:01:16

在 AS3 中,您可以使用 loaderinfo 属性获取加载的 SWF 的高度:

// imports
    import flash.display.LoaderInfo;

// loading code
    var loader:Loader = new Loader();
    loader.load(new URLRequest('some_swf.swf'));
    loader.contentLoaderInfo.addEventListener(Event.INIT, loaderInitHandler);

// listener
    function loaderInitHandler(event:Event):void 
    {
        var info:LoaderInfo = event.target as LoaderInfo;
        trace('Loaded swf is ' + info.width + ' x ' + info.height + ' px');
    }

// Loaded swf is 500 x 300 px

In AS3 you CAN get the height of a loaded SWF with the loaderinfo property:

// imports
    import flash.display.LoaderInfo;

// loading code
    var loader:Loader = new Loader();
    loader.load(new URLRequest('some_swf.swf'));
    loader.contentLoaderInfo.addEventListener(Event.INIT, loaderInitHandler);

// listener
    function loaderInitHandler(event:Event):void 
    {
        var info:LoaderInfo = event.target as LoaderInfo;
        trace('Loaded swf is ' + info.width + ' x ' + info.height + ' px');
    }

// Loaded swf is 500 x 300 px
隔纱相望 2024-07-30 02:01:16

尝试

stage.width; 
stage.height;

try

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