如何获取嵌入图像/swf 的大小?

发布于 2024-07-30 02:07:49 字数 639 浏览 5 评论 0原文

通常,如果您从 URL 加载图像,您将执行以下操作:

m_image = new Image();
m_image.addEventListener(Event.COMPLETE, image_completeHandler, false, 0, true);
m_image.source = "http://www.example.com/image.jpg";

private function image_completeHandler(event:Event):void
{
    // Image content has now loaded, we need to wait for it to validate it's size
    m_image.addEventListener(FlexEvent.UPDATE_COMPLETE, image_updateCompleteHandler, false, 0, true);
}

private function image_updateCompleteHandler(event:FlexEvent):void
{
    // Do stuff with width / height
}

但是,如果您将源设置为嵌入图像类,则完整事件似乎不会触发。 所以我的问题是,如何获得嵌入图像/swf 的宽度/高度?

Normally if you were loading an image from a URL you would do the following:

m_image = new Image();
m_image.addEventListener(Event.COMPLETE, image_completeHandler, false, 0, true);
m_image.source = "http://www.example.com/image.jpg";

private function image_completeHandler(event:Event):void
{
    // Image content has now loaded, we need to wait for it to validate it's size
    m_image.addEventListener(FlexEvent.UPDATE_COMPLETE, image_updateCompleteHandler, false, 0, true);
}

private function image_updateCompleteHandler(event:FlexEvent):void
{
    // Do stuff with width / height
}

But, if you set the source to an embedded image class, the complete event doesn't appear to fire. So my question is, how can you get the width / height of an embedded image / swf?

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

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

发布评论

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

评论(1

我们只是彼此的过ke 2024-08-06 02:07:50

任何嵌入式资源的启动都是同步的(我认为唯一的例外是 Loader.loadBytes),因此一旦执行此操作,您就可以访问其所有属性:

image = new EmbeddedImage();
trace(image.width, image.height);

The instatiation of any embedded asset is syncronous (I think the only exception is Loader.loadBytes), so as soon as you do it you can access all its properties:

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