如何在应用程序初始化之前在 Flex 中预加载文件
问题: XML 配置文件需要在运行时加载,并在调用应用程序的 createChildren() 时准备好。最晚,因为需要配置值来正确初始化子组件。最好,我希望在创建应用程序之前完成配置加载。简而言之,我想这样做:
- 加载配置,然后
- 使用加载的配置初始化应用程序。
我创建了一个自定义预加载器来帮助解决这个问题。但事实证明,当尚未保证加载配置时,应用程序的 createChildren() 方法已经在预加载期间被调用。也就是说,在自定义预加载器调度 COMPLETE 事件之前。
感谢您提前提供的任何帮助。
Problem: An XML configuration file needs to be loaded at runtime and be ready when the application's createChildren() gets called. At the latest, because configuration values are needed to properly initialize child components. Preferably, I would like the configuration loading be complete before the application even gets created. In short, I want to do this:
- load configuration, then
- initialize the application using the loaded configuration.
I created a custom preloader to help solve this. But as it turns out, the application's createChildren() method already gets called during preloading, when the configuration is not yet guaranteed to be loaded. That is, before the custom preloader dispatches the COMPLETE event.
Thanks for any help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决问题的办法。关键是捕获预加载器的 FlexEvent.INIT_PROGRESS 事件,将其排队,并停止其传播,直到配置完全加载。这有效地阻止框架继续进行应用程序初始化。配置加载后,重新分派排队的事件,让框架完成预加载阶段。下面的示例代码(仅相关部分):
要在应用程序中使用它:
I found a solution to the problem. The key was to catch the preloader's FlexEvent.INIT_PROGRESS event, queue it, and stop its propagation until the configuration is fully loaded. This effectively stops the framework to proceed with application initialization. After the configuration loads, redispatch the queued events, letting the framework finish the preloading phase. Example code below (only relevant pieces):
To use it in the application:
最简单的方法(我认为)是创建一个“持有者”画布,它将在加载上下文文件后创建应用程序内容,即:(
伪代码)
Application.mxml:
MyApplicationContent.mxml
The simplest way (I think) is to create a 'holder' canvas that will create the applications content after the context file is loaded, ie:
(psuedo code)
Application.mxml:
MyApplicationContent.mxml