1 Reply Latest reply on May 14, 2009 8:29 AM by Michael Borbor

    Passing data to an itemRenderer

    SiHoop Level 1

      How do I pass a variable to an itemRenderer? The file below uses an item renderer: BgItemRender which at the moment assigns text using this.text=data.difficulty with the result that the contents of data.difficulty shows up in every field. How can I set this.text to be the whatever field is using the itemRenderer?

       

      <?xml version="1.0"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">               
      <mx:XML id="myXml">
           <TABLE>
              <EXAMPLE1>
                 <difficulty> 0.2 </difficulty>
                 <discrimination> 0.3 </discrimination>
              </EXAMPLE1>
            </TABLE>
      </mx:XML>
      <mx:Canvas>                                    
           <mx:DataGrid dataProvider="{myXml.EXAMPLE1}" >
                <mx:columns>
                     <mx:DataGridColumn id="column1" headerText="difficulty" dataField="difficulty" itemRenderer="BgItemRenderer"/>
                     <mx:DataGridColumn id="column2"  headerText="discrimination" dataField="discrimination" itemRenderer="BgItemRenderer"/>
                </mx:columns>
           </mx:DataGrid>
      </mx:Canvas>
      </mx:Application>
      

       

      BgItemRenderer.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Label xmlns:mx="http://www.adobe.com/2006/mxml">
        <mx:Script>
          <![CDATA[
            override protected function updateDisplayList(unscaledWidth:Number, 
              unscaledHeight:Number):void{
              super.updateDisplayList(unscaledWidth,unscaledHeight);
              trace("content="+data.dataField)       
              this.text = data.difficulty;         
            }
          ]]>
        </mx:Script>
      </mx:Label>
      
        • 1. Re: Passing data to an itemRenderer
          Michael Borbor Level 4

          Declare the rendered online and set the data to be display from the 

          item renderer column and not from the component.

           

          Sincerely,

           

          Michael

           

          El 14/05/2009, a las 9:56, SiHoop <forums@adobe.com> escribió:

           

          >

          How do I pass a variable to an itemRenderer? The file below uses an 

          item renderer: BgItemRender which at the moment assigns text using 

          this.text=data.difficulty with the result that the contents of 

          data.difficulty shows up in every field. How can I set this.text to 

          be the whatever field is using the itemRenderer?

          >

          <?xml version="1.0"?>

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">      & 

          nbsp;

          <mx:XML id="myXml">

               <TABLE>

                  <EXAMPLE1>

                     <difficulty> 0.2 </difficulty>

                     <discrimination> 0.3 </discrimination>

                  </EXAMPLE1>

                </TABLE>

          </mx:XML>

          <mx:Canvas>              & nbsp;            &nb sp;

               <mx:DataGrid dataProvider="{myXml.EXAMPLE1}" >

                    <mx:columns>

                       & nbsp; <mx:DataGridColumn id="column1" 

          headerText="difficulty" dataField="difficulty" 

          itemRenderer="BgItemRenderer"/>

                       & nbsp; <mx:DataGridColumn id="column2"  

          headerText="discrimination" dataField="discrimination" 

          itemRenderer="BgItemRenderer"/>

                    </mx:columns>

               </mx:DataGrid>

          </mx:Canvas>

          </mx:Application>

          >

          >

          BgItemRenderer.mxml

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

          <mx:Label xmlns:mx="http://www.adobe.com/2006/mxml">

            <mx:Script>

              <![CDATA[

                override protected function 

          updateDisplayList(unscaledWidth:Number,

                  unscaledHeight:Number):void{

                  super.updateDisplayList(unscaledWidth,unscaledHeight);

                  trace("content="+data.dataField)

                  this.text = data.difficulty;

                }

              ]]>

            </mx:Script>

          </mx:Label>

          >

          >