开发者

list component as3

开发者 https://www.devze.com 2023-01-24 15:21 出处:网络
My list component for some reason is not displaying the data being pulled from an xml file Here is the code even though when i do a trace over \"question1\" Array i get the values.

My list component for some reason is not displaying the data being pulled from an xml file Here is the code even though when i do a trace over "question1" Array i get the values. Could any one be able to tell me what am i doing wrong here?

impor开发者_开发技巧t 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);
        }


When accessing an xml property, the return value is typed as XMLList which fl.data.DataProvider doesn't handle when building its internal array. Give this a try:

question1.push(myXML.questions[i].@idno.toString());

Another option is to let DataProvider build the data right from the xml but you'll likely need a labelField or labelFunction, try something like this:

list.dataProvider=new DataProvider(myXML);
list.labelField = "idno";

Also, you may want to access the question node in a item click handler in which case you can build your source array like so:

question1.push({
    label:myXML.questions[i].@idno.toString(),
    data:myXML.questions[i]
});
0

精彩评论

暂无评论...
验证码 换一张
取 消