FlashCS6を使用しています-AdobeAIR3.3: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
}
}
このコードは現在、「for」ループと「if」ループに実際に「food」と「monday」を入力した場合にのみ機能します。助言がありますか?
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
}
}