在应用程序启动/初始化之前加载 Flex 中的 xml 文件
我有一个配置 xml 文件,需要在加载 Flex 应用程序之前解析该文件的值。
我创建了一个静态类,允许检索 xml 配置文件中的值。
我在应用程序首次加载时初始化此类,但当 xml 文件使用同步加载的 Loader 类加载时,在实际加载 xml 文件之前会要求该类提供值 - 因此它会引发错误。
有没有办法同步加载这个 xml 文件,或者有人可以建议解决这个问题吗? 我们无法将文件作为类变量嵌入,因为我们需要能够远程更改值。
I've got a configuration xml file that I need to parse for values before a flex application laods.
I've created a static class that allows for the values in the xml config file to be retrieved.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要重写设置初始化函数。
You'll want to override the set initialized function.
使用状态怎么样? 默认状态在 xml 加载时显示一个微调器,并且加载过程的完整事件的处理程序更改为另一个状态,删除微调器并添加主容器。
不,您无法在 Flex 中同步加载文件。
How about using states? Default state shows a spinner while the xml loads, and the handler for the complete event of the loading process changes to another state that removes the spinner and adds your main container.
And no, you cannot load a file synchronously in Flex.
不错的伎俩,Quoo,但是……
必须处理在框架调用之前加载 XML 文件的情况
初始化=真。
像这样的东西:
private var _fileLoaded:Boolean =false;
private var _initialized:Boolean =false;
private function xmlCompleteHandler (event :Event) :void
//处理xml
_fileLoaded = true;
super.initialized =_fileLoaded && _初始化;
}
覆盖已初始化的公共函数集(值:布尔值):void {
_初始化=值;
super.initialized =_fileLoaded && _初始化;
}
Nice trick, Quoo, but...
One have to handle the case where XML file has been loaded BEFORE frameworks call
initialized = true.
Something like this :
private var _fileLoaded:Boolean =false;
private var _initialized:Boolean =false;
private function xmlCompleteHandler (event :Event) :void
//handle the xml
_fileLoaded = true;
super.initialized =_fileLoaded && _initialized;
}
override public function set initialized (value : Boolean) :void{
_initialized = value;
super.initialized =_fileLoaded && _initialized;
}
我发现当应用程序上线时,覆盖初始化属性并不能很好地处理。
相反,您最好使用属性creationPolicy。 当设置为“none”时,此属性将暂停容器的子级创建,直到调用方法 createComponentsFromDescriptors。
I have found that overriding the initialized property does not handle very well when the application is put online.
Instead, you're better off using the property creationPolicy. When set to 'none', this property puts on hold the child creation of the container until the method createComponentsFromDescriptors is called.
回复:贾米...
createComponentsFromDescriptors();
现在是createDeferredContent();
re: Jami ...
createComponentsFromDescriptors();
is nowcreateDeferredContent();