views:

71

answers:

2

I am loading an image into a movie clip via AS3, and what I want to do is center the image inside the movieclip. The problem is that I can't seem to grab the width value of the image being loaded. Below is what I'm doing:

imageLoader = new Loader();
imageLoader.load(new URLRequest(event.target.name));
screenBox.screenHolder.addChild(imageLoader);
trace(this.imageLoader.width);

When I trace the width, it always comes back at zero(0) even though there is an image inside the imageLoader. What is it I need to do to find the actual width so I can center the image?

A: 

http://stackoverflow.com/questions/2998189/actionscript-retrieving-width-height-of-loader-image/2998256#2998256

you have to load it first

imageLoader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedImage);
imageLoader.load(new URLRequest(event.target.name));
screenBox.screenHolder.addChild(imageLoader);

function loadedImage(event:Event):void {
   trace(event.target.content.width);
}
Dan Heberden
when I try this, the loadedImage function never fires.
HeroicNate
my bad, updated answer
Dan Heberden
now that works. Thanks man!
HeroicNate
A: 

Have you tried doing validateNow() after adding the imageLoader and before you try to get its width?

Robusto