Ikbel
Ikbel

Reputation: 7851

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?

Upvotes: 0

Views: 252

Answers (3)

Ikbel
Ikbel

Reputation: 7851

I found a solution which worked for me by placing the loaded movie inside a container and resizing the container itself instead of resizing the loader.

Upvotes: 0

null
null

Reputation: 5255

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.

Upvotes: 1

Antizam
Antizam

Reputation: 216

Try instead of width and height using scaleY and scaleY:

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

Upvotes: 0

Related Questions