2009-08-04 51 views
0

一般来说,如果你是从一个URL加载图像,你会做到以下几点:如何获取嵌入式图像/ swf的大小?

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 
} 

但是,如果你的源设置为嵌入式图像类,整个事件似乎并不火。所以我的问题是,如何获得嵌入式图像/ swf的宽度/高度?

回答

2

任何嵌入资产的instatiation是syncronous(我认为唯一的例外是Loader.loadBytes),所以只要你做到这一点,你可以访问其所有属性:

image = new EmbeddedImage(); 
trace(image.width, image.height); 
+0

这表明装载ISN嵌入即使“T同步: http://livedocs.adobe.com/flex/3/langref/mx/core/MovieClipLoaderAsset.html#event:complete – 2009-08-05 10:29:57