Use loadClip to retrieve dynamic properties
Ever had the need to load an external image and retrieve its height and width, possibly to center it? If you used loadMovie, chances are you just ended up very frustrated because the values returned were either wrong or non-existent. The reason for this is that the code you’re using to collect the imported object’s properties is executing before the image has finished loading. These situations can be incredibly frustrating and time-consuming to troubleshoot. Especially since, many times, it executes properly from the Flash IDE.
The solution is actually quite simple.
By utilizing loaders and listeners you can accurately gather all the data you need about an imported object. Here’s a simple example:
As you can see, when loadClip is used, the height and width are properly reported because, by utilizing a listener, we’ve ensured that we are not requesting properties of an object that is not yet loaded.
-rG
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.



Should this break down when one is using a movieClipLoader? I am doing almost exactly this, but keep getting zeroes from the _width and _height of the container into which the image is being loaded. Right now, I’m just trying to trace the properties, referencing the target_mc from the loader’s .onLoadComplete function, thinking that the width must be available by then..buuut, no luck. I’m kind of freaking out b/c I’m doing this for work. Any ideas or wild guesses would be hugely appreciated. Thanks.
p.s. – re: the pic – I love Japanese advertising.
…I’m a doof,…onLoadInit…nevermind
To bad the download doesn’t work, makes this post useless.
Fixed the link. Sorry all.
Thank you so much! I’ve been going insane over this issue. I was trying all sorts of techniques; getting dimensions only after total bytes are loaded, addlistener to loadMovie, etc.
You are the man!