我有一个问题,而从XML文件中的动作脚本3阅读。
I have a problem while reading from XML file in action script 3.
这是我的XML文件:
<config>
<production>
<app_id>123</app_id>
<server_path>http://someLinktoAccess</server_path>
<assets_server>http://someLinktoAccess</assets_server>
<payment_url_callback>http://someLinktoAccess</payment_url_callback>
</production>
<stage>
<app_id>123</app_id>
<server_path>http://someLinktoAccess</server_path>
<assets_server>http://someLinktoAccess</assets_server>
<payment_url_callback>http://someLinktoAccess</payment_url_callback>
</stage>
<dev>
<app_id>123</app_id>
<server_path>http://someLinktoAccess</server_path>
<assets_server>http://someLinktoAccess</assets_server>
<payment_url_callback>http://someLinktoAccess</payment_url_callback>
</dev>
</config>
我要访问的每个键 - 值对在该文件中。所以我想从这里4字符串变量来获得:APP_ID,的server_path,assets_server,payment_url_callback。我怎样才能让他们??
现在我用这样的code:
Now I'm using such a code:
private function loadXmlConfig():void
{
//load the loading config xml
var xmlLoader:URLLoader = new URLLoader();
var load_config_path:String = "http://dl.dropbox.com/u/28744968/android_vs.xml";
xmlLoader.addEventListener(Event.COMPLETE, xmlConfigLoadingSuccessed);
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlConfigLoadingFailed);
xmlLoader.load( new URLRequest( load_config_path ) );
}
private function xmlConfigLoadingSuccessed(event:Event):void
{
var load_config:XML = new XML( event.target.data );
trace(load_config.config.dev.app_id.value);
//startup facade
GameFacade.getInstance().startup( StartupCommand, this );
}
该文件被加载的所有值,但我不能访问它们。
The file is loaded with all values, but I can't access any of them.
什么意思的:
var library:XML
library.@url
感谢您!
在使用XML类,你不引用根节点你的情况配置
When using XML class you do not reference the root node in your case "config"
// your code
trace(load_config.config.dev.app_id.value);
// correct code
// the toString method should be called automatically
trace(load_config.production.app_id);
并回答您的其他问题。
And to answer your other question.
var library:XML
library.@url
@符号来访问属性。
the @ symbol is used to access attributes.
<library id=123 >
你为什么把你的配置文件作为一个XML呢? 这种类型的事情我创建一个配置文件/类/辛格尔顿的。
Why are you putting your config file as an xml anyway? This Type of thing I create a config file/class/Singleton for.