Hi All
I am working on a UIcomponent based item renderer and am getting some odd behaviour.
In my set data function I call invalidateProperties and invalidateDisplayList. I then get updateDisplayList being called before commitProperties and updateDisplayList is not then called again.
I was under the belief that commitProperties was always suppsoed to get called first in the lifecycle.
I suppose that I can just call invalidateProperties in the set data then call invalidateDisplayList in the commitProperties call but this doesn't seem quite right.
My code:
override public function set data( value : Object ) : void
{
if( data == value )return;
super.data = value;
_assetUpdate = true;
var factory : DisplayObjectFactory = data as DisplayObjectFactory;
var name : String = factory ? factory.displayName : "";
trace( "set data: " + name );
invalidateProperties();
invalidateDisplayList();
}
override protected function measure():void
{
measuredWidth = 300;
measuredHeight = 200;
}
override protected function commitProperties() : void
{
super.commitProperties();
if( _assetUpdate )
{
removeAsset();
var factory : DisplayObjectFactory = data as DisplayObjectFactory;
_txtClassName.text = factory ? factory.displayName : null;
toolTip = factory ? factory.swcFileName : null;
trace( "setting text: " + _txtClassName.text );
if( factory )
{
_asset = factory.newInstance();
addChild( _asset );
trace( "setting asset: " + getQualifiedClassName( _asset ) );
}
_assetUpdate = false;
}
}
override protected function updateDisplayList(
w : Number,
h : Number
) : void
{
super.updateDisplayList( w, h );
if( w == 0 || h == 0 )return;
_txtClassName.width = w - padding*2;
_txtClassName.height = _txtClassName.measuredHeight;
_txtClassName.x = padding;
_txtClassName.y = h - ( _txtClassName.height + padding );
if( _asset )
{
var assetBounds : Rectangle = new Rectangle(
padding,
padding,
w - padding*2,
h - ( padding*2 ) - _txtClassName.height
);
trace( "ClassRenderer updateDisplayList: " + w + " : " + h + " : " + assetBounds + " : " + _txtClassName.text );
AssetHelper.positionAsset( _asset, assetBounds );
}
graphics.clear();
graphics.beginFill( 0xFFFFFF, 1 );
graphics.drawRect( 0, 0, w, h );
}