I am using Flash CS6 – Adobe AIR 3.3:
Instead of typing exactly what I’d like to search for in my XML, I’d like to use a dynamic variable that can be changed to search for different categories and days. The following is something like the code I’d like to use:
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
}
}
This code works currently ONLY if I actually type “food” and “monday” in the ‘for’ and ‘if’ loop. Any suggestions?
The XML would be…
<xml>
<food>
<monday>yes</monday>
</food>
<food>
<monday>yes 2</monday>
</food>
<food>
<monday>un</monday>
</food>
</xml>
Here’s what currently works:
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
}
}
Copied your code and stepped through changing each part step by step and seemed to get the same result with each change I made so I believe what’s below is correct.