pointer
06-09-2009, 06:48 PM
I am testing a very simple itemRenderer for the List control, the problem is that the itemRenderer set data method is being called three times, instead of one. I know this because I am tracing the data value when the set data metod is called. Why is this happening? See below.
[Bindable]
private var simpleArray:Array = new Array("one", "two", "three", "four","five");
[Bindable]
private var theData:ArrayCollection = new ArrayCollection (simpleArray);
<mx:List itemRenderer="com.myTestClasses.renderers. testDataAmount" dataProvider="{theData}"/>
//This is my custom itemRenderer
package com.myTestClasses.renderers
{
import mx.containers.HBox;
import mx.controls.Label;
import mx.core.IDataRenderer;
public class testDataAmount extends HBox
{
private var nameLabel:Label;
private var ageLabel:Label;
private var appearanceLabel:Label;
private var _data:Object;
public function testDataAmount() {
super();
}
override public function get data():Object {
if(_data != null) {
return _data;
}
return null;
}
override public function set data(value:Object):void {
super.data = value;
trace ("value test: " + value);
_data = value;
}
}
}
// This is the trace statement output
value test: one
value test: one
value test: two
value test: three
value test: four
value test: five
value test: one
value test: two
value test: three
value test: four
value test: five
[Bindable]
private var simpleArray:Array = new Array("one", "two", "three", "four","five");
[Bindable]
private var theData:ArrayCollection = new ArrayCollection (simpleArray);
<mx:List itemRenderer="com.myTestClasses.renderers. testDataAmount" dataProvider="{theData}"/>
//This is my custom itemRenderer
package com.myTestClasses.renderers
{
import mx.containers.HBox;
import mx.controls.Label;
import mx.core.IDataRenderer;
public class testDataAmount extends HBox
{
private var nameLabel:Label;
private var ageLabel:Label;
private var appearanceLabel:Label;
private var _data:Object;
public function testDataAmount() {
super();
}
override public function get data():Object {
if(_data != null) {
return _data;
}
return null;
}
override public function set data(value:Object):void {
super.data = value;
trace ("value test: " + value);
_data = value;
}
}
}
// This is the trace statement output
value test: one
value test: one
value test: two
value test: three
value test: four
value test: five
value test: one
value test: two
value test: three
value test: four
value test: five