Actionscript 3 将组件列为3
出于某种原因,我的列表组件没有显示从xml文件中提取的数据 下面是代码,即使当我跟踪“question1”数组时,我得到了值。 谁能告诉我我做错了什么Actionscript 3 将组件列为3,actionscript-3,list,components,dataprovider,Actionscript 3,List,Components,Dataprovider,出于某种原因,我的列表组件没有显示从xml文件中提取的数据 下面是代码,即使当我跟踪“question1”数组时,我得到了值。 谁能告诉我我做错了什么 import fl.controls.List; import fl.data.DataProvider; var myXML:XML; var list:List = new List ;// new list item var question1:Array = new Array();
import fl.controls.List;
import fl.data.DataProvider;
var myXML:XML;
var list:List = new List ;// new list item
var question1:Array = new Array();
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("quiz1.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void
{
myXML = new XML(e.target.data);
list.setSize(200,200);
var xpos = (stage.stageWidth / 2) - (list.width / 2);
var ypos = (stage.stageHeight / 2) - (list.height / 2);
list.move(xpos,ypos);
for (var i:int=0; i<myXML.*.length(); i++)
{
question1.push(myXML.questions[i].@idno);
trace(question1);
}
list.dataProvider=new DataProvider(question1);
addChildAt(list,0);
}
导入fl.controls.List;
导入fl.data.DataProvider;
var-myXML:XML;
变量列表:列表=新列表;//新列表项
变量问题1:数组=新数组();
var myLoader:urloader=newurloader();
load(新的URLRequest(“quiz1.xml”);
myLoader.addEventListener(Event.COMPLETE,processXML);
函数processXML(e:Event):void
{
myXML=新的XML(e.target.data);
列表。设置大小(200200);
var xpos=(stage.stageWidth/2)-(list.width/2);
var ypos=(stage.stageHeight/2)-(list.height/2);
移动列表(XPO、YPO);
对于(var i:int=0;i在访问xml属性时,返回值被键入为XMLList,而fl.data.DataProvider在构建其内部数组时不会处理该值。请尝试一下:
question1.push(myXML.questions[i].@idno.toString());
另一种选择是让DataProvider直接从xml构建数据,但您可能需要labelField或labelFunction,请尝试以下操作:
list.dataProvider=new DataProvider(myXML);
list.labelField = "idno";
此外,您可能希望访问项目单击处理程序中的问题节点,在这种情况下,您可以像这样构建源数组:
question1.push({
label:myXML.questions[i].@idno.toString(),
data:myXML.questions[i]
});