如何获得嵌入式图像/ swf的大小?

时间:2009-08-04 21:06:47

标签: actionscript-3 size flex3

通常,如果您从URL加载图像,则执行以下操作:

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的宽度/高度?

1 个答案:

答案 0 :(得分:2)

任何嵌入资产的实例都是同步的(我认为唯一的例外是Loader.load Bytes),所以只要你这样做就可以访问它的所有属性:

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