XML data in Combo and List comps


hi there!

i new scripting. yet trying simple ones. have fla combobox[mycb], list comp[mylist], , textarea[myta] on stage. have simple external xml file below:

 

my intension list categories in combobox (distict lables). on selecting one, list comp lists edibles under category in combo. on selecting edible in list component, displays content in textarea.

 

--------------

edibles.xml

----------------

<?xml version="1.0" encoding="utf-8"?>

<edibles>

          <item id="1">

                    <cate>fruit</cate>

                    <nam>apple</nam>

          </item>

          <item id="2">

                    <cate>fruit</cate>

                    <nam>pine apple</nam>

          </item>

          <item id="3">

                    <cate>fruit</cate>

                    <nam>wood apple</nam>

          </item>

          <item id="4">

                    <cate>fruit</cate>

                    <nam>custard apple</nam>

          </item>

          <item id="5">

                    <cate>vegetable</cate>

                    <nam>bitter groud</nam>

          </item>

          <item id="6">

                    <cate>vegatable</cate>

                    <nam>carrot</nam>

          </item>

          <item id="7">

                    <cate>vegetable</cate>

                    <nam>pumkin</nam>

          </item>

          <item id="8">

                    <cate>vegetable</cate>

                    <nam>kale greens</nam>

          </item>

</edibles>

------------------------------

here as3 code

--------------------------

import flash.net.urlloader;

import flash.events.event;

import flash.net.urlrequest;

 

 

var xmldata:xml = new xml();

var catear:array = new array();

var namear:array = new array();

var loader:urlloader = new urlloader();

loader.addeventlistener(event.complete, loaddata);

loader.load(new urlrequest("edibles.xml"));

 

 

function loaddata(e:event):void{

          xmldata = new xml(e.target.data);

          //trace(xmldata..cate.length());

          for(var i:uint=0;i<xmldata..cate.length();i++){

                    catear.push(xmldata..cate[i]);

                    namear.push(xmldata..nam[i]);

                    mycb.additem( { label: catear[i], data:i } );

                    mycb.addeventlistener(event.change, listit);

          }

          parsedata(xmldata);

}

 

 

function parsedata(nams:xml):void{

          var namlist:xmllist = nams.nam;

          for each(var nlist:xml in namlist){

                    mylist.additem({label:nlist, data:nlist});

          }

}

function listit(e:event):void{

          var no:number = number(mycb.selecteditem.data);

    trace(namear[no]);

}

-----------------------------------

the problem have is:

 

1. combobox displayes items. not distict items. mean lists duplicates.

2. list component not list item on selecting category in combo

3. onselecting combo item outputs item.

 

please me. appreciate time , help.

thank you

kristtee

 

here fla file:https://docs.google.com/open?id=0byholdbl5njbdep4bkdyq2rpnfe

the code tell do.  loop have parsing data filling lists directly whereas want manage data bit more before store it, , process bit more when select it.

 

you should store each set object, meaning parse on item node rather cate/nam nodes.  store of these objects in array. 

 

after array filled, go thru , create array of of different categories, using array.indexof() method on second array determine if item (cate) exists in not duplicate any.  use second array fill combobox.

 

then, when select 1 of items in combobox, have code search thru first array objects have selected category , add them list component (probably add entire object data element of each).



More discussions in ActionScript 3


adobe

Comments