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;
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您设置图像来源时,您必须等待它加载内容。添加一个事件监听器,例如
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