views:

191

answers:

1

Normally if you were loading an image from a URL you would do the following:

m_image = new Image();
m_image.addEventListener(Event.COMPLETE, image_completeHandler, false, 0, true);
m_image.source = "http://www.example.com/image.jpg";

private function image_completeHandler(event:Event):void
{
    // Image content has now loaded, we need to wait for it to validate it's size
    m_image.addEventListener(FlexEvent.UPDATE_COMPLETE, image_updateCompleteHandler, false, 0, true);
}

private function image_updateCompleteHandler(event:FlexEvent):void
{
    // Do stuff with width / height
}

But, if you set the source to an embedded image class, the complete event doesn't appear to fire. So my question is, how can you get the width / height of an embedded image / swf?

+2  A: 

The instatiation of any embedded asset is syncronous (I think the only exception is Loader.loadBytes), so as soon as you do it you can access all its properties:

image = new EmbeddedImage();
trace(image.width, image.height);
Cay
This indicates that the loading isn't synchronous even when embedding:http://livedocs.adobe.com/flex/3/langref/mx/core/MovieClipLoaderAsset.html#event:complete
Mark Ingram
AFAIK, you don't need to use MovieClipLoaderAsset for embedded assets...
Cay