flex 4 图像尺寸

发布于 2024-12-09 02:17:00 字数 791 浏览 0 评论 0原文

我试图让图像尺寸在动态精灵对象中居中,但高度和宽度属性为 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;
}

I am trying to get the image dimensions to center in the dynamic sprite object but I am getting 0 in the height and widh property. Can some one please help me to get the image dimensions? I tried by using various properties of image control but I am getting the dimensions. Please see code below and the values in the inline comments

mxml code:

<mx:Image id = "imgActive" visible="false" />

event handler:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心病无药医 2024-12-16 02:17:00

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

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

希望这有帮助,

布莱兹

When you set the source of the image you'll have to wait for it to load the content. Add an event listener like imgActive.addEventListener(Event.COMPLETE, onImgActiveComplete);

When the image is loaded, the onImgActiveComplete handler function will be called and you can then get the dimensions of the image for example by using imgActive.content.width and imgAcive.content.height respectively.

Hope this helps,

Blaze

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文