1 Reply Latest reply on Feb 21, 2007 10:52 PM by jpwrunyan

    itemRenderer in List control

    sdsdfsdwefdcgdgcvedb Level 1
      Well guys, I seem stuck with a wall trying to make List control working with programmable dataProvider and itemRenderer defined as a component. The naive example from flex2 dev guide (p. 723 "Using an item renderer with a List control") is working fine, but in real word we are hardly coding dataProvider inline, so I tried to change this example and got absolutely nothing in my browser window:

      main application:
      ---------------------
      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" height="700" width="700" creationComplete="initApp()">
      <mx:Script>
      <![CDATA[
      import flash.events.Event;
      import flash.net.URLRequest;
      import mx.utils.ArrayUtil;
      import mx.collections.ArrayCollection;

      [Bindable]
      private var u:URLRequest;
      private var jobArray: Array = new Array();
      private var myAC: ArrayCollection = null;

      private function initApp():void {
      var myObj1:Object = {label:"Alaska", data:"Juneau", webPage:" http://www.state.ak.us/"};
      var myObj2:Object = {label:"Alabama", data:"Montgomery", webPage:" http://www.alabama.gov/"};
      jobArray.push(myObj1);
      jobArray.push(myObj2);
      myAC = new ArrayCollection(jobArray);
      }
      ]]>
      </mx:Script>
      <mx:List id="myList"
      height="180" width="250" variableRowHeight="true"
      itemRenderer="RendererState" backgroundColor="white" dataProvider="myAC">
      </mx:List>
      </mx:Application>

      itemRenderer component:
      --------------------------------
      <?xml version="1.0"?>
      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" >
      <mx:Script>
      <![CDATA[
      import flash.events.Event;
      import flash.net.URLRequest;

      private var u:URLRequest;

      private function handleClick(eventObj:Event):void {
      u = new URLRequest(data.webPage);
      navigateToURL(u);
      }
      ]]>
      </mx:Script>

      <mx:HBox >
      <mx:Label id="State" text="State: {data.label}"/>
      <mx:Label id="Statecapital" text="Capital: {data.data}" />
      </mx:HBox>
      <mx:LinkButton id="webPage" label="Official {data.label} web page"
      click="handleClick(event);" color="blue" />
      </mx:VBox>

      Anyone?
        • 1. Re: itemRenderer in List control
          jpwrunyan Level 1
          Ug, why won't adobe let us use tabs in our messages? Just to make everyone's code harder to read? Anyway...

          the very first thing I notice is that your list's dataProvider has no brackets "{}" to link it to the object. Seems that should throw an error though... however, there is a way to mess up your browser by installing the new Flash 9 player without installing the new SDK so that you don't actually get to see the errors that are thrown. So be careful there.

          First see if the brackets is an issue. Even if it doesn't throw an error, since you aren't binding the dataProvider property it may only load the ArrayCollection once when it is still empty and not after you have pushed the new data. You might also try setting the dataProvider directly in AS code: list.dataProvider = [obj1, obj2]

          I recommend adjusting your code in various ways first before finally giving up and posting here. Often that will narrow down the problem and make it easier to address.

          Finally, if you are thinking of having multiple focusable controls in your itemRenderer/Editor (this goes for either List or DataGrid) you should abandon the idea right away. Last I checked, tab focus will not pass correctly between individual renderers (at least not on IE). My solution is to simply use a Repeater. It has more overhead and you have to fiddle with scroll bars a bit, but it is a much more stable and robust solution.

          Anyway good luck.