为了缩小为什么其他人的AIR应用程序今天没有加载任何东西,并用这段代码发现了(BUG?)怪癖:
public static function getScreenDataByID(id:String="",dispose:Boolean = true) : XMLList {
var xml:XML = assets.getXml("app-data");
var screen:XMLList = new XMLList(xml.screen.(@id == id));
trace('screen=', screen);
return screen;
}
//output: screen=
经过大量的敲击后,我将其更改为:
public static function getScreenDataByID(id:String="",dispose:Boolean = true) : XMLList {
var xml:XML = assets.getXml("app-data");
var newId:String = id.toString();
var screen:XMLList = new XMLList(xml.screen.(@id == newId));
trace('screen=', screen);
return screen;
}
//output: screen=**correct data from xml***
这是Flash中的错误吗?
我从未遇到过这样的事情。
为了澄清,传递给函数的id是一个类似'home'的String,并且已经是String类型。
并且assets.getXml函数在两种情况下都返回了正确的xml。
<?xml version="1.0" encoding="utf-8" ?>
<screens>
<screen id = "home">
<id>01</id>
<name>home</name>
<title>home screen</title>
<desc>here goes description for a home screen</desc>
<descTitle>here goes desc title</descTitle>
<hasZoom>false</hasZoom>
<data>***correct data from xml</data>
</screen>
<!-- more screens -->
</screens>