开发者

Flash AS3 loading XML into listbox

I am able to load my XML file into flash and trace results. Want to populate listbox with information from xml file.

Structure of xml file:

   <eBorders> 
    <item> 
        <thumb>borderTh/blank_th.jpg</thumb>
        <file>border/blank.jpg</file>       
    </item>
    <item>开发者_C百科; 
        <thumb>borderTh/border1_th.jpg</thumb>
        <file>border/border1.jpg</file>     
    </item>
</eBorders>

AS3 code:

var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("xml/borders.xml"));

var dp:DataProvider = new DataProvider("borders.xml");

border_lb.dataProvider = dp;
border_lb.iconField = "iconSource";
border_lb.rowHeight = 45;

function processXML(e:Event):void {
myXML = new XML(e.target.data);
for(var i:int=0;i<myXML.*.length(); i++){
    dp.addItem({iconSource:myXML.item.thumb.[i]});
    }
}

Code is producing error I can't find.

Thank you in advance for any help you might offer.

Annie


I think there is some items missing from your explanatiion that would help clarify your problem.

For example, the processXML function is being triggered by an event (e:Event) but that event isn't shown.

Also, it's unclear what exactly border_lb is (i.e. is it an Object, a Dictionary?).

That being said, I think the key line to change is:

iconSource:myXML.item.thumb.[i]

to

iconSource:myXML.item.thumb.text()[i]

OR

iconSource:myXML.item.thumb[i] // minus the period

See example:

import fl.data.DataProvider;


var myXML:XML = <eBorders> 
    <item> 
        <thumb>borderTh/blank_th.jpg</thumb>
        <file>border/blank.jpg</file>       
    </item>
    <item> 
        <thumb>borderTh/border1_th.jpg</thumb>
        <file>border/border1.jpg</file>     
    </item>
</eBorders>;

var dp:DataProvider = new DataProvider();
var border_lb:Dictionary = new Dictionary();
border_lb.dataProvider = dp;
border_lb.iconField = "iconSource";
border_lb.rowHeight = 45;

function processXML():void {

for(var i:int=0;i < myXML.*.length(); i++){

    trace(myXML.item.thumb.text()[i]);
    dp.addItem({iconSource:myXML.item.thumb.text()[i]});
    }
}

processXML();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜