在应用程序启动/初始化之前,在flex中加载xml文件 [英] Load xml file in flex before application start/initialises

查看:174
本文介绍了在应用程序启动/初始化之前,在flex中加载xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经创建了一个静态类,允许使用

当应用程序第一次加载时,我初始化了这个类,但是当xml文件加载了一个Loader类来加载同步的类正在被要求值之前的XML文件实际加载 - 所以它是抛出一个错误。

有没有办法加载这个XML文件同步或可以任何人都可以提出一个解决方法?我们不能将该文件作为类变量嵌入,因为我们需要能够远程更改这些值。

解决方案

覆盖已设置的初始化函数。

 <?xml version =1.0encoding =utf-8?> 
xmlns:mx =http://www.adobe.com/2006/mxml
preinitialize =preInitHandler(event)>

< mx:Script>
<![CDATA [

private function preInitHandler(event:Event):void
{
//加载xml,将xmlCompleteHandler添加为侦听器


private function xmlCompleteHandler(event:Event):void
{
//处理xml
super.initialized = true;


重写public function set initialized(value:Boolean):
void
{
//不要做任何事情,所以我们等到xml加载
}

]]>
< / mx:Script>

< / mx:应用程序>


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.

解决方案

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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆