Reputation: 8737
I have a Flash Builder application which uses URLs within its code and I want to be able to change these URL values without having to recompile my application, i.e. I want to have a plain text file I can edit which is used to populate these URL values when the application begins. I've worked out what feels like a kludge to do this with ResourceBundles, but maybe there's a better or more straightforward way to go about this.
As an example here's what I have now:
var myUrl = "http://hard.coded.url";
I'd prefer to have the application read a properties file and set the variable accordingly:
var myUrl = getApplicationProperty("myUrl");
How would I go about writing getApplicationProperty()
? Is there a process cooked into ActionScript for this, or do I need to do it myself by opening a text (or XML) file and reading the properties as key/value pairs?
Thanks in advance for any suggestions.
Upvotes: 1
Views: 1244
Reputation: 4919
As Neeraj said it will be very fast to accomplish with your own class. Create a singleton that loads your config, parse it and your done! Or even easier solution - create your config as xml file and load it.
About ini files here a quick search result: https://stackoverflow.com/a/589725/965722
EDIT There is another way: you can create a custom preloader class that will load your config at runtime. https://stackoverflow.com/a/2788565/965722 - quick search with google.
Upvotes: 1
Reputation: 8532
If you just want a config file with key=value thing you can use your own class which reads a config file passed to it and returns a AssociativeArray back to you.
It should be a pretty straightforward thing and should not take more than 20 minutes to get done.
Upvotes: 1
Reputation: 2837
You can certainly link to properties in .properties files (used for localization for example)
See http://www.visible-form.com/blog/flex-localization-with-resource-bundles/ for an example.
That said these get compiled in the swf and the only way to read them at runtime is to write your own properties parser.
In other words, XML would be the better fit for this case.
Upvotes: 1