之前,应用程序启动/ intialises Flex中加载XML文件应用程序、加载、文件、Flex

2023-09-08 13:47:17 作者:斩猪

我有我需要之前Flex应用程序laods解析为值的配置XML文件。

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文件加载加载一个同步的类被要求为XML文件前值实际加载的Loader类 - 所以它抛出一个错误

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>