4 Replies Latest reply on Mar 2, 2007 12:52 PM by peterent

    Custom configuration file

    tnirenstein Level 1
      I want to create some app settings for a Flex app that will load on startup. I am working to implement this by using URLRequest and URLLoader to access the XML file I created which contains the settings? Is this the best way to do this or is there a better way?

      Thanks!
        • 1. Re: Custom configuration file
          peterent Level 2
          Let's assume you want to load up an XML file with your settings. Use HTTPService with resultFormat="e4x". Once the result has been delivered to the Flex app, you can easily read the values using e4x syntax.
          • 2. Re: Custom configuration file
            cluebcke Level 1
            What Peter is advising is exactly what I'm doing. It works fine.
            • 3. Re: Custom configuration file
              ebrentnelson Level 1
              I am new to Flex 2 and I am wanting load an config XML into my Flex app and store them "globally" so that I can access them from everywhere in my app (for example, I want to store the URL to my datasource on the server).

              I have tried a simple "global" test by putting: var hostname:String = " http://10.0.0.1"; in a mx:Script tag right in my mx:Application tag, but when I try to reference the variable I get "access to an undefined variable hostname".

              How would I go about doing this? Thanks.
              • 4. Re: Custom configuration file
                peterent Level 2
                Make sure make your variable public:

                public var hostname:String = "whatever you want";

                Then, from anywhere in your application: Application.application.hostname

                You'll need to add: import mx.core.Application; to any Script block where you use that.

                When you say Application.application the first Application refers to the class, Application. The .application refers to a static variable inside of the Application class. This is a reference to your main MXML class file. And of course, .hostname refers to your variable.