Is it possible to load a .properties file from a client computer using adobe flex? I have a flex app that needs to access a server and multiple URLs but the URLs may change frequently. So I think modifying and loading the URLs from a .properties file would be the easiest way update the URLs. Any suggestions? Thanks.
Thanks for the answers. I was able to use florians suggestion and I've added the code below if anyone else is interested. I used the example here URLLoader.
public function URLLoaderDataFormatExample(event:Event):void
{
var request:URLRequest = new URLRequest("file:///c:/temp/prop.properties");
var variables:URLLoader = new URLLoader();
variables.dataFormat = URLLoaderDataFormat.VARIABLES;
variables.addEventListener(Event开发者_如何转开发.COMPLETE, completeHandler);
try
{
variables.load(request);
}
catch (error:Error)
{
trace("Unable to load URL: " + error);
}
}
private function completeHandler(event:Event):void
{
var loader:URLLoader = URLLoader(event.target);
trace(loader.data.dayNames);
}
]]>
</fx:Script>
HTTPService or URLLoader should both work.
The Parsley Flex framework has a nice way of achieving this as well - http://www.spicefactory.org/parsley/docs/2.4/manual/config.php#properties
Possibly overkill if all you want are some simple properties but perhaps worth a look in the future. Otherwise Florian's suggestion of using HTTPService or URLLoader will work.
Basically there are two possibilities to load .properties files in Flex.
The first possibility would be to open a File using flash.filesystem.File. It should be quite simple to manually parse the .properties file then and extract the data. You should keep in mind that this will only work for applications based on Adobe Air because web applications are not allowed to access files outside of their sandbox.
The second possibility involves resource modules. You can use them to externalize configuration data instead of localization data as well. However, using resource modules requires to recompile your application whenever your .properties file changes.
精彩评论