1 Reply Latest reply on Jan 14, 2008 11:31 AM by JKohn99

    Static Initializtion

      Hi folks!

      I've been working for some time with flex, but not enough to know the answer for that. In java applications it's common to have a configuration file loaded before the main application is initialized, enabling one to use the XML to configure the app (like Spring beans for instance).

      I'd like to have something similar in my flex client: I have a list of services that can be accessed by the client, and I'd like to have the services url's in a XML file that would be loaded before the application initializes. I'm trying to use a Preloader for that, but the problem is that I can't find a way to delay the main application initialization. I'd like to have the XML to be loaded before the Application object is initialized, so that, when a Application's initialize event is dispatched, the XML content is avaiable for the application.

      What currently happens is that, in the Preloader, when the first INIT_PROGRESS event is dispatched, I load the XML using a URLLoader and register the proper event handlers for the loader. But, when the first INIT_PROGRESS is dispatched the Application is initialized, while the XML is being loaded. The result is that some of the information in the XML is not avaiable by the time the main Application requests it.

      Did anybody ever try to do something like this? If so, did anybody manage to find a solution for the problem?
        • 1. Re: Static Initializtion
          JKohn99 Level 1
          We do the same thing. Load some xml that contains service addresses that we use for subsquent retrievals.

          There is a preinitialize handler on the application tag. Use this to
          setup the event handlers to be invoked when your xml is ready.

          So you then don't need to use the initialized application tag, user your own to then do what ever your app needs to do first.

          The following app loads some xml and only enables the button after the xml is available.
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"


          private var parms:XML = null;
          public function startUp():void
          private function gotXml(event:Event):void
          dispatchEvent(new Event("startApplication"));
          private function startApplication(event:Event):void
          ptext.text = parms.toXMLString();
          readyBtn.enabled = true;
          private function completeHandler(event:Event):void
          parms = new XML(event.currentTarget.data);
          dispatchEvent(new Event("gotXml"));
          private function errorHandler(event:Event):void

          private function fetchParms():void
          var url:String = " http://lp008400:8080/WsdlServer/appParms.xml";
          var request:URLRequest = new URLRequest(url);

          var variables:URLLoader = new URLLoader(request);
          variables.dataFormat = URLLoaderDataFormat.TEXT;
          variables.addEventListener(Event.COMPLETE, completeHandler);
          <mx:TextArea x="34" y="25" height="243" id="ptext"/>
          <mx:Button x="48" y="289" label="Ready button" enabled="false" id="readyBtn"/>

          In our case we also use a custom preloader since the xml we load takes a long time to fetch.