tags:

views:

316

answers:

1

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> 
        <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

A: 

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();
redconservatory
border_lb is listbox.processXML triggered by complete loading of xml document - code changed: var dp:DataProvider = new DataProvider();border_lb.dataProvider = dp;border_lb.iconField = "iconSource";border_lb.rowHeight = 45;var myXML:XML;var myLoader6:URLLoader = new URLLoader();myLoader6.load(new URLRequest("xml/borders.xml"));myLoader6.addEventListener(Event.COMPLETE, processXML);function processXML(e:Event):void {myXML = new XML(e.target.data);for(var i:int=0;i<myXML.*.length(); i++){ trace(myXML.item.thumb.[0]); dp.addItem({iconSource:myXML.item.thumb.text()[i]}); }}
Anne
Would like to add icons or thumbnails to a listbox that is named border_lb. The icons are stored in folder borderTh and the file name is border1_th.jpg. In the XML file that is the child element <thumb>. The actual image that the icon represents is in the border folder and the file name is border1.jpg. In the XML file that is the child element <file>.Now I need to populate the border_lb with the icon and data.Thank you for your time.Annie
Anne