This content has been marked as final. Show 4 replies
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.
What Peter is advising is exactly what I'm doing. It works fine.
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.
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.