Flex 4图像尺寸



我试图在动态精灵对象中获得图像尺寸,但我在高度和宽度属性中获得0。有没有人可以帮我得到图像的尺寸?我尝试使用图像控制的各种属性,但我得到的尺寸。请参阅下面的代码和内联注释

中的值

mxml代码:

<mx:Image id = "imgActive" visible="false" />
事件处理程序:

  private function addImageHandler(e:MyCustomeEve){
            imgActive.source = e.imageUrl; 
            imgActive.visible = true;
            GAME_STATUS = "ITEM_SELECTED";
            trace(imgActive.width,
                imgActive.height, // 0
                imgActive.contentHeight, // 0
                imgActive.contentWidth, // NaN
                imgActive.content.width, // error because imgActive.content is null
                imgActive.content.height  // error because imgActive.contentis null);
            imgActive.cacheAsBitmap = true;
}

当您设置图片的来源时,您必须等待它加载内容。添加一个事件侦听器,如imgActive.addEventListener(Event.COMPLETE, onImgActiveComplete);

当图像被加载时,onImgActiveComplete处理函数将被调用,然后你可以获得图像的尺寸,例如分别使用imgActive.content.width和imgactive .content.height。

希望有帮助,

火灾

最新更新