A. Mueller
A. Mueller

Reputation: 21

ActionScript 3 Loader - swf disappears as soon as loader.width is set

I'm using a Loader object to load an external swf:

var swfLoader:Loader = new Loader();
stage.addChild(swfLoader);
var bgURL:URLRequest = new URLRequest("sometestfile.swf");

swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);

swfLoader.x = 240;
swfLoader.y = 210;

// Resize here?

swfLoader.load(bgURL);
function loadProdComplete(e:Event):void
{
    trace("File loaded");
}

This works fine until I try to set swfLoader.width or .height (as I do when I want to resize loaded images), but in this case the swf isn't displayed anymore. (It's running anyway as I receive traces from sometestfile.swf)

I've resolved my error, using swfLoader.content.width in the Complete event works.

Upvotes: 2

Views: 1713

Answers (2)

daihovey
daihovey

Reputation: 3575

You should add stage.addChild(swfLoader); and swfLoader.x = 240; swfLoader.y = 210; and the height and width settings to the loadProdComplete()

Upvotes: 1

grapefrukt
grapefrukt

Reputation: 27045

The loader will have zero width/height until the COMPLETE event fires, so wait until then to set the size. That may solve your problem.

Upvotes: 2

Related Questions