views:

223

answers:

1

I have one xml file like below

<tree>
<branch1><node1/><node2/><node3/><branch1>
<brach2><node1/><node2/><node3/><branch1>
<branch3><node1/><node2/><node3/><branch1>
<branch4><node1/><node2/><node3/><branch1>
</tree>

I have one combobox which is populated with

branch1
branch2
branch3

Now i want that when branch 1 is selected then combobox2 should automatically loads with

node1
node2
node3

My CUrrent code is

for each(var element:XML in testXML.elements()) {
                    comboFar.addItem({label:element.name(),label:element.name()});

                }
A: 

You should assign an event handler for combobox1 like:

    var myXML:XML= <tree>
                       <branch name='1'><node name='1'/><node name='2'/><node name='3'/></branch>
                       <branch name='2' ><node name='1'/><node name='2'/><node name='3'/></branch>
                       <branch name='3'><node name='1'/><node name='2'/><node name='3'/></branch>
                   </tree> // or something like this



    combobox1.addEventListener(Event.CHANGE,changeListener); 


    function changeListener(e:Event):void
    {
         populateCombobox2(myXML.branch.(@name == e.currentTarget.selectedItem.@name));
    }

    function populateCombobox2(combo2Data:XML):void
    {
        combobox2.dataSource = combo2Data;
        combobox2.displayName = "@name"; // I don't remember if this is correct, and I can't 
                                         //check it now, but this is the logic.... if its not 
                                         //correct tell me, and when I get home I can tell you 
                                         //the correct way
    }
Biroka