Why do you think the renderer's commitProperties is being called more than
once for a single item?  Your trace statements do not identify the item.
You understand that there is no direct relationship between the number of
items and the number of renderer instances?  The number of instances depends
on the number of visible rows, plus a few for buffering.

 

And are you just curious?  The specific renderer instantiation behavior is
normally not of concern to a developer, but  such concern sometimes
indicates misuse.

 

Tracy

 

  _____  

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of flexrookie
Sent: Saturday, February 28, 2009 9:35 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] redundancy in custom ItemRenderer

 

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. <http://www.adobe.com/2006/mxml>
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