tags:

views:

66

answers:

2
[Bindable]
            private var company:XML =

              <list>
                <department title="Finance" code="200">
                    <employee name="John H"/>

                    <employee name="Sam K"/>
                </department>
                <department title="Operations" code="400">

                    <employee name="Bill C"/>
                    <employee name="Jill W"/>
                </department>                    
                <department title="Engineering" code="300">

                    <employee name="Erin M"/>
                    <employee name="Ann B"/>
                </department>                                
              </list>;

private function addEmployee():void

            {
                var newNode:XML = <employee/>;
                newNode.@name = empName.text;
                var dept:XMLList =company.department.(@title == "Operations");
                if( dept.length() > 0 ) {

                    dept[0].appendChild(newNode);
                    empName.text = "";
                }
            }

The Particular code adds a new node to the operations, but i want to add a node any item i select.

+1  A: 

Try using an XMLList and then looping through the department nodes inspecting their department title each time.

I am a little unsure as to what exactly you want to do though.

robmcm
+1  A: 

Add a combo box (myCombobox) for the user to select where to add user (ie Operations, Finance, Engineering). Based on selected Department add to specific list:

 private function addEmployee():void
        {
            var newNode:XML = <employee/>;
            newNode.@name = empName.text;

            var dept:XMLList;

            switch(myCombobox.selectedLabel){
                 case 'Operations':
                     dept = company.department.(@title == "Operations");
                     break;

                 case 'Finance':
                     dept = company.department.(@title == "Finance");
                     break;

                 case 'Engineering':
                     dept = company.department.(@title == "Engineering");
                     break;
            }

            if( dept.length() > 0 ) {

                dept[0].appendChild(newNode);
                empName.text = "";
            }
        }
Jeff Pinkston
Thanks a lot mate