简体   繁体   中英

AS3: How to resize an External Loaded SWF?

I'm trying to import an external SWF using the code below:

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;

}

When trying to resize, the external movie disappears. Where am I wrong?

Try Event.INIT instead. Some things are available in Event.COMPLETE and some in the other, despite the fact that the order of their occurrence is fixed, which would suggest that everything is possible in the later one, but that's not the case.

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.

I know what the documentation of the init event says:

The init event always precedes the complete event.

So everything should be available in the event that is fired last, right? According to experience that's not the case. Time and time again changing one event to the other solved the problem that was always similar to the one given in this question.

The first link also state this, very relevant to this question:

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.

Try instead of width and height using scaleY and scaleY:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM