获取Flex中嵌入图像的宽度和高度?

时间:2023-01-19 20:29:07

I have the follow declaration :

我有以下声明:

[Embed(source="i/6.png")]
private var img6 : Class;
  • How can i determine "img6" width and height ?
  • 我怎样才能确定“img6”的宽度和高度?

1 个解决方案

#1


1  

You can determine size of embed image only on instantiation. Something like:

您只能在实例化时确定嵌入图像的大小。就像是:

<s:BitmapImage source="{img6}" complete="completeHandler(event)" />
…
private function completeHandler(event:Event):void
{
    var image:BitmapImage = BitmapImage(event.currentTarget);
    trace (image.sourceWidth);
    trace (image.sourceHeight);
}

#1


1  

You can determine size of embed image only on instantiation. Something like:

您只能在实例化时确定嵌入图像的大小。就像是:

<s:BitmapImage source="{img6}" complete="completeHandler(event)" />
…
private function completeHandler(event:Event):void
{
    var image:BitmapImage = BitmapImage(event.currentTarget);
    trace (image.sourceWidth);
    trace (image.sourceHeight);
}