Upload xml file to flex before running / initializing the application

I have an xml configuration file that I need to parse for values ​​before flexes the application.

I created a static class that allows you to retrieve values ​​in an xml configuration file.

I initialize this class when the application first loads, but since the xml file is loaded with the Loader class, which loads synchronously, the class is requested for values ​​before the xml file is actually loaded, so it throws an error.

Is there any way to download this xml file synchronously or can anyone suggest working with this? We cannot embed a file as a class variable, since we must be able to modify values ​​remotely.

+3
source share
5 answers

You want to override the installed 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>
+7
source

How about using states? The default state shows the counter while xml is loading, and the handler for the full event of the loading process changes to another state, which removes the counter and adds your main container.

And no, you cannot upload a file synchronously to Flex.

0
source

, Quoo, ... , XML initialized = true.

- : private var _fileLoaded: Boolean = false;
private var _initialized: Boolean = false;

xmlCompleteHandler (: ): void
// xml
_fileLoaded = true;
super.initialized = _fileLoaded && & _initialized;
}
override public function set initialized (value: Boolean): void {
_initialized = ;
super.initialized = _fileLoaded && & _initialized;

}

0

, , .

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>
0
source

re: Jami ... createComponentsFromDescriptors();nowcreateDeferredContent();

0
source

Source: https://habr.com/ru/post/1713219/


All Articles