在应用程序启动/初始化之前加载 Flex 中的 xml 文件

发布于 2024-07-27 05:27:33 字数 253 浏览 8 评论 0原文

我有一个配置 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

ぃ弥猫深巷。 2024-08-03 05:27:33

您需要重写设置初始化函数。

   <?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>

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>
温柔女人霸气范 2024-08-03 05:27:33

使用状态怎么样? 默认状态在 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.

旧伤还要旧人安 2024-08-03 05:27:33

不错的伎俩,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;

}

千柳 2024-08-03 05:27:33

我发现当应用程序上线时,覆盖初始化属性并不能很好地处理。

相反,您最好使用属性creationPolicy。 当设置为“none”时,此属性将暂停容器的子级创建,直到调用方法 createComponentsFromDescriptors。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="absolute"
                preinitialize="{loadStuff();}"
                creationPolicy="none">

<mx:Script>
    <![CDATA[

        private function loadStuff():void {
            // Load your stuff here
        }

        private function loadStuffHandler(event:Event):void {
            // This should be called when loading (from loadStuff method) finishes
            createComponentsFromDescriptors();
        }

    ]]>
</mx:Script>

</mx:Application>

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.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="absolute"
                preinitialize="{loadStuff();}"
                creationPolicy="none">

<mx:Script>
    <![CDATA[

        private function loadStuff():void {
            // Load your stuff here
        }

        private function loadStuffHandler(event:Event):void {
            // This should be called when loading (from loadStuff method) finishes
            createComponentsFromDescriptors();
        }

    ]]>
</mx:Script>

</mx:Application>
坐在坟头思考人生 2024-08-03 05:27:33

回复:贾米...
createComponentsFromDescriptors(); 现在是 createDeferredContent();

re: Jami ...
createComponentsFromDescriptors(); is now createDeferredContent();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文