AS3:如何调整外部加载的 SWF 文件的大小?

AS3: How to resize an External Loaded SWF?

我正在尝试使用以下代码导入外部 SWF:

var r:URLRequest = new URLRequest("movie.swf");
var imageLoader:Loader = new Loader(); 

imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);

imageLoader.load(r);
addChild(imageLoader);

function onLoadComplete(e:Event):void
{
    imageLoader.width  = 100;
    imageLoader.height = 75;

}

尝试调整大小时,外部影片消失了。我哪里错了?

试试 Event.INIT。有些东西在 Event.COMPLETE 中可用,有些在另一个中可用,尽管它们出现的顺序是固定的,这表明在后一个中一切皆有可能,但事实并非如此。

As per comment, I dug out an old link explaining the matter.

A very similar event to the Event.COMPLETE is the Event.INIT which is triggered when the external asset is ready to be used, whether fully downloaded or not. For example, the very few frames of an external SWF might be ready for display before the entire file is downloaded, so you might want to do something with these frames while you want for the rest of the movie to download. On the other hand, some files might be fully downloaded but not yet initialized as the initialization might take a second or two after the completion of the download process of a file, so you might want to wait for this file to be ready for usage before attempting to use that asset.

我知道 what the documentation of the init 事件说:

The init event always precedes the complete event.

所以最后触发的事件中的所有内容都应该可用,对吧? 根据经验,情况并非如此。一次又一次地将一个事件更改为另一个事件解决了总是与这个问题中给出的问题相似的问题。

第一个link也是这么说的,跟这个问题很相关:

Event.INIT is commonly used when attempting to retrieve the width and height of an image when it finishes loaded. Such property is not available instantly when the file finishes loading, so attempting to retrieve these properties using Event.COMPLETE fails, Event.INIT must be used instead.

尝试使用 scaleY 和 scaleY 代替宽度和高度:

imageLoader.scaleX  = 0.5;   // 50%
imageLoader.scaleY  = 0.3;   // 30%

我找到了一个对我有用的解决方案,方法是将加载的电影放在容器中并调整容器本身的大小,而不是调整加载器的大小。