【问题标题】:flex 4 image dimensionsflex 4 图像尺寸
【发布时间】:2011-10-11 07:34:23
【问题描述】:

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

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;
}

【问题讨论】:

  • 您正在收听的事件是什么?

标签: actionscript-3 image flex4 dimensions


【解决方案1】:

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

当图像被加载时,onImgActiveComplete 处理函数将被调用,然后您可以通过分别使用 imgActive.content.width 和 imgAcive.content.height 来获取图像的尺寸。

希望这会有所帮助,

火焰

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-27
  • 1970-01-01
  • 1970-01-01
  • 2015-02-28
相关资源
最近更新 更多