[flexcoders] Re: redundancy in custom ItemRenderer

2009-03-03 Thread flexrookie
> 2) I don't think you can make a variable bindable by putting [Bindable] 
> AFTER the variable (unless you were intending to make your button 
> variable bindable on dataChange).
--
right, that was an error in my code. it should go before the getter,
as in:

=
// Make the data property bindable.
[Bindable("dataChange")]
public function get data():Object {
return _data;
}
=

thanks for pointing that out.



[flexcoders] Re: redundancy in custom ItemRenderer

2009-03-02 Thread Amy
--- In flexcoders@yahoogroups.com, "flexrookie"  wrote:
>
> 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.

Some suggestions: 

1) Use a flag in set data so that you don't go through your logic in 
commitProperties that's only relevant when data changes when 
commitProperties is called for other reasons.
2) I don't think you can make a variable bindable by putting [Bindable] 
AFTER the variable (unless you were intending to make your button 
variable bindable on dataChange).
3) There's a lot of overhead in adding and removing children.  Consider 
hiding and showing instead.



[flexcoders] Re: redundancy in custom ItemRenderer

2009-03-02 Thread flexrookie
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"  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.




[flexcoders] Re: redundancy in custom ItemRenderer

2009-03-02 Thread flexrookie
thanks amy,
i found that info confirmed by alex harui's famous itemrenderer post,
under recycling, here:
http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html

~flexrookie

--- In flexcoders@yahoogroups.com, "Amy"  wrote:
>
> --- In flexcoders@yahoogroups.com, "flexrookie"  wrote:
> >
> > 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. 
> 
> http://flexdiary.blogspot.com/2008/04/is-horizontallist-faster-than-
> hbox-with.html
>




[flexcoders] Re: redundancy in custom ItemRenderer

2009-03-02 Thread flexrookie
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.

i am curious, partly from a performance perspective, and partly
because i want to understand how this works so i can slowly become
better at architecting flex apps. code follows. 

StockApp.mxml


http://www.adobe.com/2006/mxml";
layout="absolute"
  applicationComplete="applicationCompleteListener(event)">

  




StockInfoRenderer.as

package {
  import mx.containers.Canvas;
  import mx.controls.Button;
  
  public class StockInfoRenderer extends Canvas {
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);
}

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

  button.label = data.stockInfo.getPrice();
}

override public function set data (value:Object):void {
  super.data = value;
  trace("StockInfoRenderer SET DATA CALLED for ID: " + data.id);
  invalidateProperties()
}
  }
}


StockInfo.as

package {
  import flash.events.Event;
  import flash.events.EventDispatcher;
  import flash.events.TimerEvent;
  import flash.utils.Timer;

  public class StockInfo extends EventDispatcher {
private var t:Timer;

public function StockInfo () {
  t = new Timer(1000);
  t.addEventListener(TimerEvent.TIMER, timerListener);
  t.start();
}

public function timerListener (e:TimerEvent):void {
  dispatchEvent(new Event("UPDATE"));
}

public function getPrice ():Number {
  return Math.floor(Math.random()*1000)/100;
}
  }
}


output

StockInfoRenderer CONSTRUCTOR CALLED.
StockInfoRenderer CREATE CHILDREN CALLED.
StockInfoRenderer SET DATA CALLED for ID: 1
StockInfoRenderer COMMIT PROPERTIES CALLED for ID: 1
StockInfoRenderer SET DATA CALLED for ID: 1
StockInfoRenderer COMMIT PROPERTIES CALLED for ID: 1

StockInfoRenderer CONSTRUCTOR CALLED.
StockInfoRenderer SET DATA CALLED for ID: 1
StockInfoRenderer CREATE CHILDREN CALLED.
StockInfoRenderer COMMIT PROPERTIES CALLED for ID: 1


~flexrookie


--- In flexcoders@yahoogroups.com, "Tracy Spratt"  wrote:
>
> 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
> ===
> 
> http://www.adobe.

> com/2006/mxml"
> layout="absolute"
> applicationComplete="applicationCompleteListener(event)">
> 
> 
> 
> 
> ===
> 
> 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();
> butt

[flexcoders] Re: redundancy in custom ItemRenderer

2009-03-02 Thread flexrookie
> ~flashrookie
--
er...

flexrookie (flash masta!) ; )



[flexcoders] Re: redundancy in custom ItemRenderer

2009-03-01 Thread Amy
--- In flexcoders@yahoogroups.com, "flexrookie"  wrote:
>
> 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. 

http://flexdiary.blogspot.com/2008/04/is-horizontallist-faster-than-
hbox-with.html