问题描述
我有一个配置 xml 文件,我需要在 flex 应用程序加载之前解析它的值.
I've got a configuration xml file that I need to parse for values before a flex application laods.
我创建了一个静态类,允许检索 xml 配置文件中的值.
I've created a static class that allows for the values in the xml config file to be retrieved.
我在应用程序第一次加载时初始化这个类,但是当 xml 文件加载了一个同步加载的 Loader 类时,在实际加载 xml 文件之前要求类提供值 - 所以它抛出一个错误.
I'm initialising this class when the application first loads but as the xml file is loaded with a Loader class that loads a synchronously the class is being asked for values before the xml file is actually loaded - so it is throwing a error.
有没有办法同步加载这个 xml 文件,或者有人可以建议解决这个问题吗?我们不能将文件作为类变量嵌入,因为我们需要能够远程更改这些值.
Is there a way to load this xml file synchronously or can anyone suggest a work around to this? We cannot embed the file as a class variable as we need to be able to change the values remotely.
推荐答案
您需要覆盖设置的初始化函数.
You'll want to override the set initialized function.
<?xml version="1.0″ encoding="utf-8″?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
preinitialize="preInitHandler(event)">
<mx:Script>
<![CDATA[
private function preInitHandler (event : Event) : void
{
//load the xml, add the xmlCompleteHandler as a listener
}
private function xmlCompleteHandler (event : Event) : void
{
//handle the xml
super.initialized = true;
}
override public function set initialized (value : Boolean) :
void
{
// don't do anything, so we wait until the xml loads
}
]]>
</mx:Script>
</mx:Application>
这篇关于在应用程序启动/初始化之前在 flex 中加载 xml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!