2 Replies Latest reply on Jan 13, 2010 7:13 AM by Gregory Lafrance

    Set property of an XML string

    rick@cat

      Hi All,

      Another newbie question, sorry. I'm trying to set an attribute of some XML before adding it to a datagrid dataprovider without too much luck. Here's the code I'm trying which does not work:

       

      var newType:XML = <equipment_type

                         equip_type_id=""

                         equip_manufacturer_id=""

                         str_name="Click to add a new type"/>


      newType.attribute('equip_manufacturer_id') = dgMfg.selectedItem.@equip_manufacturer_id;
      dgType.dataProvider.addItem(newType);

       

      Basically I am trying to set the Mfgid before it gets added to the type grid. What I'm getting is "Target of assignment must be a reference value."

       

      Any ideas?

       

      Thanks,

      Rick

        • 1. Re: Set property of an XML string
          rick@cat Level 1

          I answered my own question by experimenting a little. This works:

           

          var newType:XML = <equipment_type
                             equip_type_id=""
                             equip_manufacturer_id={dgMfg.selectedItem.@equip_manufacturer_id}
                             str_name="Click here to add a new equipment type"/>

           

          Rick

          • 2. Re: Set property of an XML string
            Gregory Lafrance Level 6

            attribute() returns an attribute and cannot be used to set an attribute.

             

            Use .@myAttribute.

             

            If this post answers your question or helps, please mark it as such.


            Greg Lafrance - Flex 2 and 3 ACE certified

            www.ChikaraDev.com

            Flex / AIR Development, Training, and Support Services

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
              creationComplete="init();">
              <mx:Script>
                <![CDATA[
                  import mx.collections.XMLListCollection;
                  
                  private var xml:XML = 
                    <items>
                      <equipment_type equip_type_id="test1"
                        equip_manufacturer_id="test1"
                        str_name="test1"/>
                      <equipment_type equip_type_id="test2"
                        equip_manufacturer_id="test2"
                        str_name="test2"/>
                    </items>;
                  private var xml2:XML = 
                    <items>
                      <equipment_type equip_type_id="test1"
                        equip_manufacturer_id="test7"
                        str_name="test7"/>
                      <equipment_type equip_type_id="test8"
                        equip_manufacturer_id="test8"
                        str_name="test8"/>
                    </items>;
                    
                  [Bindable] private var xlc:XMLListCollection;
                  [Bindable] private var xlc2:XMLListCollection;
                    
                  private function init():void{
                    xlc = new XMLListCollection(xml..equipment_type);
                    xlc2 = new XMLListCollection(xml2..equipment_type);
                  }
                  
                  private function addNew():void{
                    var newType:XML = <equipment_type
                      equip_type_id=""
                      equip_manufacturer_id=""
                      str_name="Click to add a new type"/>
                    newType.@equip_manufacturer_id = dgMfg.selectedItem.@equip_manufacturer_id;
                    dgType.dataProvider.addItem(newType);        
                  }
                ]]>
              </mx:Script>
              <mx:ComboBox id="dgMfg" dataProvider="{xlc2}" 
                prompt="Add New"
                labelField="@equip_manufacturer_id" change="addNew();"/>
              <mx:DataGrid id="dgType" dataProvider="{xlc}">
                <mx:columns>
                  <mx:DataGridColumn dataField="@equip_manufacturer_id"
                    headerText="ID"/>
                </mx:columns>
              </mx:DataGrid>
            </mx:Application>