如何使用 Adobe Flex 从客户端加载 .properties 文件?
是否可以使用 adobe flex 从客户端计算机加载 .properties 文件?我有一个 Flex 应用程序,需要访问服务器和多个 URL,但 URL 可能会经常更改。因此,我认为从 .properties 文件修改和加载 URL 将是更新 URL 的最简单方法。有什么建议吗?谢谢。
感谢您的回答。我可以使用弗洛里安的建议,如果其他人感兴趣,我已经添加了下面的代码。我使用了此处的示例 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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
HTTPService 或 URLLoader 应该都可以工作。
HTTPService or URLLoader should both work.
Parsley Flex 框架也有一个很好的方法来实现这一点 -
http://www.spicefactory.org/parsley/docs/2.4 /manual/config.php#properties
如果您想要的只是一些简单的属性,但也许将来值得一看,则可能有点过分了。否则 Florian 使用 HTTPService 或 URLLoader 的建议将起作用。
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.
基本上有两种方法可以在 Flex 中加载 .properties 文件。
第一种可能性是使用 flash 打开文件.filesystem.File。然后手动解析 .properties 文件并提取数据应该非常简单。您应该记住,这仅适用于基于 Adobe Air 的应用程序,因为不允许 Web 应用程序访问其沙箱之外的文件。
第二种可能性涉及资源模块。您也可以使用它们来外部化配置数据而不是本地化数据。但是,使用资源模块需要在 .properties 文件发生更改时重新编译应用程序。
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.