第一次调用 load() 时加载模块失败,但之后会成功

发布于 2024-11-25 00:34:55 字数 2245 浏览 3 评论 0原文

我有一个按钮,单击该按钮会在我的 AIR 应用程序中加载 Flex 模块。但是,有时模块在第一次单击按钮时无法加载,但在第二次单击时可以正常工作。当我在调试器中调试它时,不会触发 READY 事件,因此永远不会调用剩余的逻辑。

var moduleInfo:IModuleInfo = ModuleManager.getModule(managedModule.url);
moduleInfo.addEventListener(ModuleEvent.READY, function(event:ModuleEvent):void {
    trace("ModuleEvent.READY called.");
});
moduleInfo.addEventListener(ModuleEvent.ERROR, function(event:ModuleEvent):void {
    trace("ModuleEvent.ERROR called.");
});
moduleInfo.addEventListener(ModuleEvent.SETUP, function(event:ModuleEvent):void {
    trace("ModuleEvent.SETUP called.");
});
moduleInfo.addEventListener(ModuleEvent.PROGRESS, function(event:ModuleEvent):void {
    trace("ModuleEvent.PROGRESS called.");
});
moduleInfo.addEventListener(ModuleEvent.UNLOAD, function(event:ModuleEvent):void {
    trace("ModuleEvent.UNLOAD called.");
});
moduleInfo.load(ApplicationDomain.currentDomain);

需要 ApplicationDomain.currentDomain 来解决其他问题,但将其保留或删除似乎并没有什么区别。有时模块无法加载。输出大致如下:

[trace] ModuleEvent.PROGRESS 已调用。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] 调用了 ModuleEvent.PROGRESS。 [SWF] MyStupidModule.swf - 解压后为 342,932 字节 [trace] 调用了 ModuleEvent.SETUP。 [trace] 调用了 ModuleEvent.PROGRESS。

注意 READY 永远不会被调用,ERROR 也不会被调用。如果我再次单击该按钮,则会打印出以下内容:

调用了 [trace] ModuleEvent.SETUP。 [trace] 调用了 ModuleEvent.PROGRESS。 [trace] ModuleEvent.READY 被调用。

有什么线索可能导致这种情况吗?我们使用的是 Flex 3.6.0 AIR 2.6.019

I have a Button that when clicked loads a Flex module in my AIR application. However, occasionally the Module fails to load the first time the button is clicked, but it works the second time it's clicked. When I debug it in the debugger the READY event is not fired so the remaining logic is never called.

var moduleInfo:IModuleInfo = ModuleManager.getModule(managedModule.url);
moduleInfo.addEventListener(ModuleEvent.READY, function(event:ModuleEvent):void {
    trace("ModuleEvent.READY called.");
});
moduleInfo.addEventListener(ModuleEvent.ERROR, function(event:ModuleEvent):void {
    trace("ModuleEvent.ERROR called.");
});
moduleInfo.addEventListener(ModuleEvent.SETUP, function(event:ModuleEvent):void {
    trace("ModuleEvent.SETUP called.");
});
moduleInfo.addEventListener(ModuleEvent.PROGRESS, function(event:ModuleEvent):void {
    trace("ModuleEvent.PROGRESS called.");
});
moduleInfo.addEventListener(ModuleEvent.UNLOAD, function(event:ModuleEvent):void {
    trace("ModuleEvent.UNLOAD called.");
});
moduleInfo.load(ApplicationDomain.currentDomain);

The ApplicationDomain.currentDomain is needed to fix other issues, but having it there or removing it doesn't seem to make a difference. Sometimes the modules just doesn't load. The output is roughly as follows:

[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.PROGRESS called.
[SWF] MyStupidModule.swf - 342,932 bytes after decompression
[trace] ModuleEvent.SETUP called.
[trace] ModuleEvent.PROGRESS called.

Notice READY is never called, and neither is ERROR. If I click the button again here is what is printed out:

[trace] ModuleEvent.SETUP called.
[trace] ModuleEvent.PROGRESS called.
[trace] ModuleEvent.READY called.

Any clues what could be causing this? We are using Flex 3.6.0 AIR 2.6.019

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

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

发布评论

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

评论(2

虐人心 2024-12-02 00:34:55

在所有者类中的某个位置存储对 ModuleInfoProxy (IModuleInfo) 的引用 - ModuleManager.getModule() 返回给您的实例,例如 ModuleInfoProxy

class MyMainClass
{
           private var moduleInfo:IModuleInfo;
           public function load():void
           {
                 moduleInfo = ModuleManager.getModule("SimpleModule.swf");
                 ...
           }    
}

使用弱引用事件,如果对象不再引用,GC 可以使用事件处理程序将其完全删除它。在局部变量中存储对 IModuleInfo 的引用使得该对象在 load() 方法退出后有资格进行 GC。如果这种情况发生在模块完全加载之前,您的侦听器将不会被回调。

Store reference somewhere in the owner class to the ModuleInfoProxy (IModuleInfo) - the instance that ModuleManager.getModule() returns for you, for example

class MyMainClass
{
           private var moduleInfo:IModuleInfo;
           public function load():void
           {
                 moduleInfo = ModuleManager.getModule("SimpleModule.swf");
                 ...
           }    
}

ModuleInfoProxy uses weak reference events and GC can remove it completely with event handlers if the object has no more reference to it. Storing a reference to IModuleInfo in a local variable makes that object eligible for GC once the load() method exits. If that happens before the module has fully loaded your listeners wouldn't be called back.

墨洒年华 2024-12-02 00:34:55

这是 SDK

http://bugs.adobe.com/ 中修复的实际错误jira/browse/SDK-14669

尝试更新到最新的兼容 SDK,您应该已经设置好了。它应该在您列出的 SDK 中修复,但不会造成损害。

如果它不适合您,我会帮助您制定解决方案。

好消息是你没有疯,这是一个框架错误。

=)

This was an actual bug that was fixed in the SDK

http://bugs.adobe.com/jira/browse/SDK-14669

Try updating to the most recent compatible SDK and you should be set. It should be fixed in the SDK you have listed, but won't hurt.

If it doesn't work for you, I'll help you craft a work around.

Good news is you aren't crazy, it's a framework bug.

=)

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