another question about ItemRenderers, using my previous stock example.

i have noticed that my custom item renderer seems to be performing
redundant executions. for a single dataProvider item, i see two
renderer instances created. and for each instance, set data and
commitProperties() are called repeatedly. 

here's my code:

StockApp.mxml
===================================
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute"
  applicationComplete="applicationCompleteListener(event)">
<mx:Script>
  <![CDATA[
    import mx.collections.ArrayCollection;
    import mx.controls.HorizontalList;
    import mx.events.FlexEvent;
    import mx.core.ClassFactory;
    
    protected var list:HorizontalList;
    protected var provider:ArrayCollection;
    
    protected function applicationCompleteListener (e:FlexEvent):void {
      // Provider
      provider = new ArrayCollection();
      provider.addItem({stockInfo:new StockInfo()});
      
      // UI
      list = new HorizontalList();
      list.width = 400;
      list.height = 100;
      list.dataProvider = provider;
      list.itemRenderer = new ClassFactory(StockInfoRenderer);
      
      addChild(list);
    } 
  ]]>
</mx:Script>
</mx:Application>
===================================

StockInfoRenderer.as
===================================
package {
  import mx.containers.Canvas;
  import mx.controls.Button;
  
  public class StockInfoRenderer extends Canvas {
    protected var button:Button;
    
    public function StockInfoRenderer () {
      trace("StockInfoRenderer CONSTRUCTOR CALLED.");
    }
    
    override protected function createChildren ():void {
      trace("StockInfoRenderer CREATE CHILDREN CALLED.");
      super.createChildren();
      
      if (button == null) {
        button = new Button();
        button.width = 100;
      }
      addChild(button);
    }
    
    override protected function commitProperties ():void {
      trace("StockInfoRenderer COMMIT PROPERTIES CALLED.");
      super.commitProperties();

      button.label = data.stockInfo.getPrice();
    }
    
    override public function set data (value:Object):void {
      trace("StockInfoRenderer SET DATA CALLED.");
      super.data = value;
      invalidateProperties()
    }
  }
}
===================================


OUTPUT:
===================================
StockInfoRenderer CONSTRUCTOR CALLED.
StockInfoRenderer CREATE CHILDREN CALLED.
StockInfoRenderer SET DATA CALLED.
StockInfoRenderer COMMIT PROPERTIES CALLED.
StockInfoRenderer SET DATA CALLED.
StockInfoRenderer COMMIT PROPERTIES CALLED.

StockInfoRenderer CONSTRUCTOR CALLED.
StockInfoRenderer SET DATA CALLED.
StockInfoRenderer CREATE CHILDREN CALLED.
StockInfoRenderer COMMIT PROPERTIES CALLED.
===================================

is the preceding redundancy typical, or am i doing something wrong?

~flashrookie

Reply via email to