我正在使用Flash CS6 - Adobe AIR 3.3: 而不是在我的XML中正好輸入我想要搜索的內容,我想使用動態變量可以更改爲搜索不同的類別和日期。下面是類似的代碼,我想使用:Adobe AIR 3.3或AS3:動態變量來搜索xml
var someCategory:String = new String("food");
var someDay:String = new String("monday");
var locationsLoader:URLLoader = new URLLoader();
locationsLoader.load(new URLRequest("http://www.myfile.xml"));
locationsLoader.addEventListener(Event.COMPLETE, init);
//load xml
function init(e:Event):void
{
theXML = new XML(e.target.data);
theXML.ignoreWhitespace = true;
e.currentTarget.close();
for(var i:int = 0; i < theXML.someCategory.length(); i++)
{
if(theXML.someCategory[i].somdDay != "un")
{
//do soemthing
}
}
此代碼的工作目前僅如果我真的鍵入「對」「食品」和「星期一」和「如果」循環。有什麼建議麼?
的XML是...
<xml>
<food>
<monday>yes</monday>
</food>
<food>
<monday>yes 2</monday>
</food>
<food>
<monday>un</monday>
</food>
</xml>
這裏是當前工作:
var someCategory:String = new String("food");
var someDay:String = new String("monday");
var locationsLoader:URLLoader = new URLLoader();
locationsLoader.load(new URLRequest("http://www.myfile.xml"));
locationsLoader.addEventListener(Event.COMPLETE, init);
//load xml
function init(e:Event):void
{
theXML = new XML(e.target.data);
theXML.ignoreWhitespace = true;
e.currentTarget.close();
for(var i:int = 0; i < theXML.food.length(); i++)
{
if(theXML.food[i].monday != "un")
{
//do soemthing
}
}
你有很多錯誤在你的代碼中,你可以請更正,例如somDay,我和someCategory這應該被鍵入爲字符串或是一個數組?你的XML在哪裏?顯示適合你的代碼。 – shaunhusain 2012-07-30 22:32:53
對不起。是的,他們是字符串。我修復了XML,並顯示了當前的工作。 – user1129107 2012-07-30 22:45:19
感謝您的糾正,請參閱下面的答案,相信這會很好地服務您的目的,而忽略將XML內聯並擺脫Loader等的事實,只是爲了便於檢查。 – shaunhusain 2012-07-30 23:14:00