6 Replies Latest reply on Aug 19, 2009 7:16 AM by saulobrust

    Flex 4 itemRenderer Problem

    Gregory Lafrance Level 6

      I'm trying to run the example application in the Flex 4 SDK beta document, page 504, but it is rendering the data as [object Object]. Any ideas what additional is necessary to get this to work?

       

      <?xml version="1.0" encoding="utf-8"?>
      <!-- containers\spark\SparkDataGroupContainerOverride.mxml -->
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
          xmlns:mx="library://ns.adobe.com/flex/halo"
          xmlns:s="library://ns.adobe.com/flex/spark"
          xmlns:MyComps="myComponents.*">
          <!-- Define a custom DataGroup container to override the itemToLabel() method. -->
          <MyComps:MyDataGroup itemRenderer="spark.skins.default.DefaultItemRenderer">
              <MyComps:layout>
                  <s:VerticalLayout/>
              </MyComps:layout>
              <mx:ArrayCollection>
                  <fx:Object firstName="Bill" lastName="Smith" companyID="11233"/>
                  <fx:Object firstName="Dave" lastName="Jones" companyID="13455"/>
                  <fx:Object firstName="Mary" lastName="Davis" companyID="11543"/>
                  <fx:Object firstName="Debbie" lastName="Cooper" companyID="14266"/>
              </mx:ArrayCollection>
          </MyComps:MyDataGroup>
      </s:Application>
      

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:SkinnableDataContainer xmlns:fx="http://ns.adobe.com/mxml/2009"
          xmlns:s="library://ns.adobe.com/flex/spark"
          xmlns:mx="library://ns.adobe.com/flex/halo">
          <s:layout>
          <s:VerticalLayout/>
          </s:layout>
          <fx:Script>
              <![CDATA[
                  import mx.core.IVisualElement;
                  import spark.components.IItemRenderer;
                  // Override to return the Object as a formatted String.
                  
                  override public function itemToLabel(item:Object):String {
                      var tempString:String;
                      if (item == null)
                          return " ";
                      tempString = item.firstName + " " + item.lastName + " " + ", ID: " + item.companyID;
                      return tempString;
                  }
              ]]>
          </fx:Script>
      </s:SkinnableDataContainer>