0
我有一個奇怪的問題。indexOf由xml填充陣列
當試圖做的indexOf在「靜態」數組,它的工作原理,做填充了XML的陣列上同樣的事情,我總是得到的結果= -1
靜態的方式
var myarray:Array = new Array("Pub Pepsi","Shadow E-Bike","Icon Air Craft","Test","La page 4","La page 5","La page 6","La page 7");
var myresult:* = myarray.indexOf("Icon Air Craft");
trace(myresult);
// I get 2 as result so it works
動態的方式(從XML)
var Monthpath:String = "juin";
var XMLpathUrl:String = "http://www.omagazine.fr/editions/2011/" + Monthpath + "/obook_content.xml.php";
var xml:XML;
var xmlLoader:URLLoader = new URLLoader();
var myarray:Array = new Array();
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void
{
xmlLoader.removeEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.removeEventListener(IOErrorEvent.IO_ERROR, xmlError);
xml = new XML(event.target.data);
for (var i in xml.pages.page)
{
myarray.push(xml.pages.page[i][email protected]);
}
var myresult:* = myarray.indexOf("Icon Air Craft");
trace(myresult);
//-------------------------------------
// I get -1 as result!!!! Why????
//-------------------------------------
}
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlError);
function xmlError(event:IOError):void
{
trace("Error");
}
xmlLoader.load(new URLRequest(XMLpathUrl));
您的XML是否有任何名稱空間?也許嘗試:xml。* :: pages。* :: page [i]。@ ga – Jim
請從源代碼示例中移動您的問題,並將其添加爲常規文本,因此更明顯的是您要完成的任務。 –