2 Replies Latest reply on Jan 3, 2008 5:18 PM by dimpled

    TileList itemRenderer's creationComplete not a good solution

    dimpled
      I'm not sure if this is a bug, or just the by-product of TileList being made a recycling component, but none-the-less here is the scenario.

      I have a Tree list that, upon itemClick, updated the dataProvider for my TileList. This alone works wonderfully, even with a custom itemRenderer.

      The caveat is when the itemRenderer uses the creationComplete event to set data, such as this:
      <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="initApp()">
      <mx:Script>
      <![CDATA[
      public function initApp():void {
      myLabel.text = data.@label;
      }
      ]]>

      <mx:Script>
      <mx:Label id="myLabel" />
      </mx:HBox>

      The issue is, upon change of the dataProvider for the TileList, the label won't be updated. My issue involved a nested TileList, but i narrowed it down to creating a label in the initApp function and using this.addChild(theLabelIMade) - still the problem existed.

      My solution, wait until the data is actually sent to the component.

      override public function set data(value:Object):void {
      if(value !=null) {
      super.data = value;
      }
      // do things like updating bindable variables, etc here
      }
        • 1. Re: TileList itemRenderer's creationComplete not a good solution
          joan_lafferty Adobe Employee
          Yes, you cannot rely on the creationComplete event in an itemRenderer. For an item renderer or item editor, Flex might reuse an instance of the item renderer. But, a reused instance of an item renderer does not redispatch the creationComplete event.

          Joan Lafferty
          Flex SDK QA
          • 2. Re: TileList itemRenderer's creationComplete not a good solution
            dimpled Level 1
            I understand what's happening under the hood - and it makes sense to conserve resources and improve performance. But shouldn't a creationComplete event be fired even if the item is recycled? I'm sure I'm not the only developer that thought well I'll just use the creationComplete event, like i do in my actual applications or popups.

            I'm not saying that overriding the 'set data' method doesn't work great, I'm just saying there should be some consistency - even if items are being recycled.

            But enough ranting! :D i just posted this so that others might stumble upon it -