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

flash, quickTip

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.

Comments

5 Responses to “Use loadClip to retrieve dynamic properties”

Leave Comment

(required)

(required)