URL请求&加载器事件监听器未针对图像触发

发布于 2024-10-08 05:18:50 字数 507 浏览 0 评论 0原文

我正在通过 URLRequest 和 Loader 类加载图像,并且我想在请求完成时管理图像。下面的示例在事件完成时不会触发该事件。相同的代码可以查找 URLLoader,但不能查找 Loader 对象。基本上图像加载并且事件侦听器永远不会被触发。谁能告诉我如何在加载程序完成加载图像时触发事件。

var imageReq:URLRequest = new URLRequest("http://www.google.com/images/nav_logo29.png");
var imageLoader:Loader = new Loader();
//
imageLoader.addEventListener(Event.COMPLETE, imageComplete);
imageLoader.load(imageReq);

addChild(imageLoader);

function imageComplete(e:Event):void {
    trace("Image Complete");
}

谢谢

I'm loading images via a URLRequest and Loader classes and I want to manage the image when the request is complete. The example below doesn't fire the event when it is complete. The same code would work find for a URLLoader, but not a Loader object. Basically the image loads and the event listener is never fired. Can anyone tell me how to get an event to fire when Loader finishes loading an image.

var imageReq:URLRequest = new URLRequest("http://www.google.com/images/nav_logo29.png");
var imageLoader:Loader = new Loader();
//
imageLoader.addEventListener(Event.COMPLETE, imageComplete);
imageLoader.load(imageReq);

addChild(imageLoader);

function imageComplete(e:Event):void {
    trace("Image Complete");
}

Thank you

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

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

发布评论

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

评论(1

慵挽 2024-10-15 05:18:50

典型的。发布后几秒钟,我找到了解决方案,认为我应该做出回应,以防其他人遇到同样的问题。

因为您正在加载另一个对象,所以您需要将事件侦听器附加到该对象。您可以使用 contentLoaderInfo 属性来执行此操作,如下所示。

imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageComplete);

Typical. Few seconds after posting I find a solution, thought I should respond in case anyone else comes across the same problem.

Because you are loading another object you need to attached your event listener to that. You can use the contentLoaderInfo property to do that, like below.

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