如何配置Air应用程序以引用外部配置文件?

时间:2022-01-08 22:59:55

I'd like to reference an external configuration (e.g., *.ini) file that will allow me to set configuration variables for each deployment of my Air application. Unfortunately, I haven't been able to find any information on the best way to approach this problem.

我想引用一个外部配置(例如* .ini)文件,该文件允许我为Air应用程序的每个部署设置配置变量。不幸的是,我无法找到有关解决此问题的最佳方法的任何信息。

With that being said, does anyone have any advice on how to make this happen?

话虽如此,有没有人对如何实现这一点有任何建议?

3 个解决方案

#1


Here's the implementation of the small xml idea:

这是小xml想法的实现:

var file:File = File.applicationDirectory.resolvePath( "config.xml" );
var stream:FileStream = new FileStream();

stream.open( file, FileMode.READ );
config = new XML( stream.readUTFBytes( stream.bytesAvailable ));
stream.close();

Just place the config.xml file in your src directory, it will appear in the installed directory when the release package gets installed. I made config a public var on my main application, so I can just do Application.application.config.someOption from anywhere in my project.

只需将config.xml文件放在src目录中,安装发行包时它就会出现在已安装的目录中。我在我的主应用程序上配置了一个public var,所以我可以从我项目的任何地方做Application.application.config.someOption。

#2


I dont know if there is an air centric way of making this happen. I haven't found any good class i the api docs. If you got a lot of configuration options there might be an idea to look for an existing library that can help you. But if you just need to store some simple settings i would just create a small xml file and parse it with E4X.

我不知道是否有以空气为中心的方式来实现这一目标。 api docs我没有找到任何好的课程。如果您有很多配置选项,可能需要寻找可以帮助您的现有库。但是如果你只需要存储一些简单的设置,我只需创建一个小的xml文件并用E4X解析它。

It might be possible to jam it inside the application descriptor but it doesn't feel like a good solution if you want someone to manually change some settings.

可能会将其卡在应用程序描述符中,但如果您希望某人手动更改某些设置,则不会感觉这是一个很好的解决方案。

#3


the easiest and simplest way is to use ticlib SimpleConfiguration, check this blog post. because it based on sharedobject it can be used both in FLEX or AIR application.

最简单最简单的方法是使用ticlib SimpleConfiguration,查看这篇博文。因为它基于sharedobject,它可以在FLEX或AIR应用程序中使用。

#1


Here's the implementation of the small xml idea:

这是小xml想法的实现:

var file:File = File.applicationDirectory.resolvePath( "config.xml" );
var stream:FileStream = new FileStream();

stream.open( file, FileMode.READ );
config = new XML( stream.readUTFBytes( stream.bytesAvailable ));
stream.close();

Just place the config.xml file in your src directory, it will appear in the installed directory when the release package gets installed. I made config a public var on my main application, so I can just do Application.application.config.someOption from anywhere in my project.

只需将config.xml文件放在src目录中,安装发行包时它就会出现在已安装的目录中。我在我的主应用程序上配置了一个public var,所以我可以从我项目的任何地方做Application.application.config.someOption。

#2


I dont know if there is an air centric way of making this happen. I haven't found any good class i the api docs. If you got a lot of configuration options there might be an idea to look for an existing library that can help you. But if you just need to store some simple settings i would just create a small xml file and parse it with E4X.

我不知道是否有以空气为中心的方式来实现这一目标。 api docs我没有找到任何好的课程。如果您有很多配置选项,可能需要寻找可以帮助您的现有库。但是如果你只需要存储一些简单的设置,我只需创建一个小的xml文件并用E4X解析它。

It might be possible to jam it inside the application descriptor but it doesn't feel like a good solution if you want someone to manually change some settings.

可能会将其卡在应用程序描述符中,但如果您希望某人手动更改某些设置,则不会感觉这是一个很好的解决方案。

#3


the easiest and simplest way is to use ticlib SimpleConfiguration, check this blog post. because it based on sharedobject it can be used both in FLEX or AIR application.

最简单最简单的方法是使用ticlib SimpleConfiguration,查看这篇博文。因为它基于sharedobject,它可以在FLEX或AIR应用程序中使用。