not an answer to my  question, but a follow up for new itemrenderer
coders. i just changed my implementation of the renderer from a canvas
to a UIComponent, following alex harui's performance recommendation.

here's the updated renderer code (big thanks to peter ent's renderer
post at
http://weblogs.macromedia.com/pent/archives/2008/04/itemrenderers_p_4.html):
===================================
package {
  import mx.core.UIComponent;
  import mx.controls.Button;
  import mx.controls.listClasses.IListItemRenderer;
  import mx.events.FlexEvent;
  
  import flash.display.Shape;
  
  public class StockInfoRenderer extends UIComponent implements
IListItemRenderer {
    private var _data:Object;
    // Make the data property bindable.
    [Bindable("dataChange")]
    
    protected var button:Button;
    
    public function StockInfoRenderer () {
      trace("");
      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);
        
        var tmp:Shape = new Shape();
        tmp.graphics.beginFill(0);
        tmp.graphics.drawRect(0,0,10,10);
        tmp.graphics.endFill();
        addChild(tmp);
        mask = tmp;
      }

    }
    
    override protected function commitProperties ():void {
      trace("StockInfoRenderer COMMIT PROPERTIES CALLED for ID: " +
data.id);
      super.commitProperties();

      if (data.id != null) {
        button.label = data.stockInfo.getPrice();
      } else {
        if (button && contains(button)) {
          removeChild(button);
        }
      }
    }
    
    // Define the getter method.
    public function get data():Object {
        return _data;
    }
    
    // Define the setter method, and dispatch an event when the property
    // changes to support data binding.
    public function set data(value:Object):void {
       _data = value;
       dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));

      trace("StockInfoRenderer SET DATA CALLED for ID: " + data.id);
      invalidateProperties()
    }


    override protected function updateDisplayList (unscaledWidth:Number,
                                                  
unscaledHeight:Number):void {
      super.updateDisplayList(unscaledWidth, unscaledHeight);
      
      if (button) {
        button.setActualSize(100, 50);
      }
      
      if (mask) {
        mask.width = unscaledWidth;
        mask.height = unscaledHeight;
      }
      setActualSize(unscaledWidth, unscaledHeight);
    }
  }
}
===================================

~flexrookie


--- In flexcoders@yahoogroups.com, "flexrookie" <flexroo...@...> wrote:
>
> ok, new code, this time with IDs on dataProvider items for tracking.
> yes, i know there's no direct renderer-to-provider relationship. i now
> realize that the extra renderer instance is created for measurment
> (according to alex harui). but i'm still looking for an explanation on
> the multiple set data and commitProperties() calls.


Reply via email to