Re: [flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
This seems like probably the best option. I suspected that it was something to do with properties changing causing excessive refresh, but the fact that Alex didn't point that out as the problem kind of threw me off track. It appears that the highlight is set in drawItem, so I subclassed ADG and overrode it, setting the highlight property. I added a bit to the highlight to make sure the event only gets fired if the value actually changes. As to your question of using selectedItem, the problem is twofold. First, the problem is that the grid doesn't provide any property for highlightedItem. Yes, as Tim said I could subclass and create one (much like I did above). But the secondary problem is that I want several bits of code that aren't interconnected to do something when a given item in the data list is active. I don't want these different bits of the code to have to know about controls and grids. I just want them to see a data element changing and respond to it. Secondly, this is complicated by the fact that I can lock some elements into the active state. So I might have item 2, 4 and 8 locked on and be mousing over item 5. The other component will show items 2, 4, 5 and 8 all active. By the way, Tim, I had composed this as a response to your suggestions but not go around to sending it to you yet: Well, the problem with that and with your example is that they rely on the itemRenderers to do the management of the highlighted variable. That was a tangent I got on to show that it wasn't just the fact that it runs through an ArrayCollection that was breaking it. The problem with the itemRenderers managing it is that there is dead space between item renderers (i.e. padding) that the renderers never see. Thanks everyone for your input on the problem! On Tue, Jun 9, 2009 at 6:12 PM, Paul Williams p_m_willi...@yahoo.co.ukwrote: When you set the highlighted property on your items, they are dispatching PropertyChangeEvents. The collection they are in will receive these PropertyChangeEvents and dispatch CollectionChangeEvents. The AdvancedDataGrid will receive these and perform a visual update, which appears to clear the rollover highlight. To prevent the rollover highlight clearing you need to avoid dispatching PropertyChangeEvents when you update the hightlighted property. Which means you need to use a custom event in your binding (see below). This should fix the choppiness without breaking the binding, although you might want to rethink this whole approach: When you select an item in a datagrid it sets the selectedItem property; it doesn't update the underlying data items. Why not follow this pattern for tracking which item is rolled over? package { import flash.events.EventDispatcher; public class TestObject extends EventDispatcher { [Bindable] public var label:String; private var _highlighted:Boolean; public function get highlighted() : Boolean { return _highlighted; } [Bindable( event = highlightedChange )] public function set highlighted( highlighted : Boolean ) : void { _highlighted = highlighted; dispatchEvent( new Event( highlightedChange ) ); } } } Pan Troglodytes wrote: 1) Yes, this works fine, for the display portion only. It doesn't address the actual problem of needing to set a flag in the data that indicates it is the currently highlighted one, that flag being also used by other things that bind to the data that don't want to know about UI details like the grid. In this case, I had a number of chart listeners that would toggle series on/off depending on which one was highlighted in the grid. 2) There is no commitProperties on AdvancedDataGridItemRenderer. Perhaps you meant validateProperties. In this example, it gets called only when the grid is first displayed and not when any item is highlighted/de-highlighted or selected/de-selected. 3) Yes, the styleFunction does get called when the highlighted object changes. But if you move the code to set data.highlighted there, you get the same result! It just seems like anything that changes this bound variable on every repaint of the cell is doomed to break the rollover highlight. On Tue, Jun 9, 2009 at 11:49 AM, Amy amyblankens...@bellsouth.netamyblankenship%40bellsouth.net wrote: --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.comflexcoders% 40yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: That was a good idea and it does get rid of the arraycollection walking. But I get the SAME problem with the grid losing highlighting when I did it using AdvancedGridItemRenderer, thought the symptoms are slightly different: Personally, I'd do one of two things: 1) Just look to see if the current item is the highlighted item in the styleFunction -or- 2) Override commitProperties instead of validateNow(). I'd also be tempted to investigate whether the styleFunction gets called when the
[flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
--- In flexcoders@yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: 1) Yes, this works fine, for the display portion only. It doesn't address the actual problem of needing to set a flag in the data that indicates it is the currently highlighted one, that flag being also used by other things that bind to the data that don't want to know about UI details like the grid. In this case, I had a number of chart listeners that would toggle series on/off depending on which one was highlighted in the grid. It seems to me that you'd be better off having a variable at the controller level that contains the item that was the last item associated with an itemRollOver event. 2) There is no commitProperties on AdvancedDataGridItemRenderer. Perhaps you meant validateProperties. In this example, it gets called only when the grid is first displayed and not when any item is highlighted/de-highlighted or selected/de-selected. Yes, I think that's a nasty little component because it has the functionality of a mushroom. I typically use a modified AdvancedDataGridGroupItemRenderer to render all columns. 3) Yes, the styleFunction does get called when the highlighted object changes. But if you move the code to set data.highlighted there, you get the same result! It just seems like anything that changes this bound variable on every repaint of the cell is doomed to break the rollover highlight. I wouldn't be trying to change the data itself in respons to a ui change, since it's almost inevitably going to trigger another ui change. HTH; Amy
Re: [flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
Yes, a mushroom indeed - well put! By the way, I found your posts about your fun with the various ADG item renderers quite informative. Though you did leave me wishing for some source code of the working examples. The problem here is that this data serves to link up different parts of the UI. It's so that many different pieces can look in one place and hook to one set of variables. It also serves as abstraction. I have a chart that I can instantiate any number of copies of (with different views of the data, etc.) I don't want this chart to have to have knowledge of this one fixed grid. The grid is also reused in a couple of different ways, so i don't want the grid to be hardcoded to the chart. It's the perils of abstraction and modularization. On Wed, Jun 10, 2009 at 4:12 PM, Amy amyblankens...@bellsouth.net wrote: --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: 1) Yes, this works fine, for the display portion only. It doesn't address the actual problem of needing to set a flag in the data that indicates it is the currently highlighted one, that flag being also used by other things that bind to the data that don't want to know about UI details like the grid. In this case, I had a number of chart listeners that would toggle series on/off depending on which one was highlighted in the grid. It seems to me that you'd be better off having a variable at the controller level that contains the item that was the last item associated with an itemRollOver event. 2) There is no commitProperties on AdvancedDataGridItemRenderer. Perhaps you meant validateProperties. In this example, it gets called only when the grid is first displayed and not when any item is highlighted/de-highlighted or selected/de-selected. Yes, I think that's a nasty little component because it has the functionality of a mushroom. I typically use a modified AdvancedDataGridGroupItemRenderer to render all columns. 3) Yes, the styleFunction does get called when the highlighted object changes. But if you move the code to set data.highlighted there, you get the same result! It just seems like anything that changes this bound variable on every repaint of the cell is doomed to break the rollover highlight. I wouldn't be trying to change the data itself in respons to a ui change, since it's almost inevitably going to trigger another ui change. HTH; Amy -- Jason
[flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
--- In flexcoders@yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: Yes, a mushroom indeed - well put! By the way, I found your posts about your fun with the various ADG item renderers quite informative. Though you did leave me wishing for some source code of the working examples. The problem here is that this data serves to link up different parts of the UI. It's so that many different pieces can look in one place and hook to one set of variables. It also serves as abstraction. I have a chart that I can instantiate any number of copies of (with different views of the data, etc.) I don't want this chart to have to have knowledge of this one fixed grid. The grid is also reused in a couple of different ways, so i don't want the grid to be hardcoded to the chart. It's the perils of abstraction and modularization. If you had one variable containing _just_ the highlighed item at the controller level, that would actually be even more abstracted and reusable than tying everything to the entire collection and forcing things to look at a property on one item of the collection. Also more efficient.
Re: [flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
I think you missed the part above where I said more than one item could be activated. Some items can be locked on, and it also includes the currently selectedItem (which can be different than the one being moused over). The examples were dumbed down so people could easily figure out where I was seeing the problem. On Wed, Jun 10, 2009 at 6:54 PM, Amy amyblankens...@bellsouth.net wrote: --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: Yes, a mushroom indeed - well put! By the way, I found your posts about your fun with the various ADG item renderers quite informative. Though you did leave me wishing for some source code of the working examples. The problem here is that this data serves to link up different parts of the UI. It's so that many different pieces can look in one place and hook to one set of variables. It also serves as abstraction. I have a chart that I can instantiate any number of copies of (with different views of the data, etc.) I don't want this chart to have to have knowledge of this one fixed grid. The grid is also reused in a couple of different ways, so i don't want the grid to be hardcoded to the chart. It's the perils of abstraction and modularization. If you had one variable containing _just_ the highlighed item at the controller level, that would actually be even more abstracted and reusable than tying everything to the entire collection and forcing things to look at a property on one item of the collection. Also more efficient. -- Jason
[flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
--- In flexcoders@yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: That was a good idea and it does get rid of the arraycollection walking. But I get the SAME problem with the grid losing highlighting when I did it using AdvancedGridItemRenderer, thought the symptoms are slightly different: Personally, I'd do one of two things: 1) Just look to see if the current item is the highlighted item in the styleFunction -or- 2) Override commitProperties instead of validateNow(). I'd also be tempted to investigate whether the styleFunction gets called when the highlighted object changes. HTH; Amy
[flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
Here is my take on what you are trying to do... Application: ?xml version=1.0 encoding=utf-8? Application xmlns=http://www.adobe.com/2006/mxml; creationComplete=cc() layout=horizontal Script ![CDATA[ import mx.events.ListEvent; import mx.collections.ArrayCollection; [Bindable] public var d:ArrayCollection = new ArrayCollection([]); private const ITEM_COUNT:int = 15; private function cc():void { for (var i:int = 0; i ITEM_COUNT; i++) { var item:TestObject = new TestObject; item.label = Item + i; d.addItem(item); } } ]] /Script AdvancedDataGrid id=list dataProvider={d} height=100% columns AdvancedDataGridColumn dataField=label itemRenderer=MyItemRenderer/ /columns /AdvancedDataGrid /Application MyItemRenderer.as: package { import flash.events.MouseEvent; import mx.collections.ArrayCollection; import mx.controls.AdvancedDataGrid; import mx.controls.LinkButton; import mx.controls.dataGridClasses.DataGridListData; public class MyItemRenderer extends LinkButton { private var theData:Object; public function MyItemRenderer() { super(); } override public function set data(value:Object):void { super.data = value; theData = value; if(value != null) { label = value[DataGridListData(listData).dataField]; if(theData.highlighted) { setStyle(fontWeight, bold); } else { setStyle(fontWeight, normal); } addEventListener(MouseEvent.MOUSE_OVER, changeDataProvider); } } private function changeDataProvider(event:MouseEvent):void { var dp:ArrayCollection = ((event.target as MyItemRenderer).owner as AdvancedDataGrid).dataProvider as ArrayCollection; var rowCount:int = 0; for each(var testObject:TestObject in dp) { if((dp[rowCount] as TestObject).label == theData.label) { (((event.target as MyItemRenderer).owner as AdvancedDataGrid).dataProvider[rowCount] as TestObject).highlighted = true; } else { (((event.target as MyItemRenderer).owner as AdvancedDataGrid).dataProvider[rowCount] as TestObject).highlighted = false; } rowCount++; } } } } HTH Steve
Re: [flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
1) Yes, this works fine, for the display portion only. It doesn't address the actual problem of needing to set a flag in the data that indicates it is the currently highlighted one, that flag being also used by other things that bind to the data that don't want to know about UI details like the grid. In this case, I had a number of chart listeners that would toggle series on/off depending on which one was highlighted in the grid. 2) There is no commitProperties on AdvancedDataGridItemRenderer. Perhaps you meant validateProperties. In this example, it gets called only when the grid is first displayed and not when any item is highlighted/de-highlighted or selected/de-selected. 3) Yes, the styleFunction does get called when the highlighted object changes. But if you move the code to set data.highlighted there, you get the same result! It just seems like anything that changes this bound variable on every repaint of the cell is doomed to break the rollover highlight. On Tue, Jun 9, 2009 at 11:49 AM, Amy amyblankens...@bellsouth.net wrote: --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: That was a good idea and it does get rid of the arraycollection walking. But I get the SAME problem with the grid losing highlighting when I did it using AdvancedGridItemRenderer, thought the symptoms are slightly different: Personally, I'd do one of two things: 1) Just look to see if the current item is the highlighted item in the styleFunction -or- 2) Override commitProperties instead of validateNow(). I'd also be tempted to investigate whether the styleFunction gets called when the highlighted object changes. HTH; Amy -- Jason
[flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
Just a thought, but what if you call drawHighlightIndicator manually; after you set the variable? Maybe even callLater. -TH --- In flexcoders@yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: 1) Yes, this works fine, for the display portion only. It doesn't address the actual problem of needing to set a flag in the data that indicates it is the currently highlighted one, that flag being also used by other things that bind to the data that don't want to know about UI details like the grid. In this case, I had a number of chart listeners that would toggle series on/off depending on which one was highlighted in the grid. 2) There is no commitProperties on AdvancedDataGridItemRenderer. Perhaps you meant validateProperties. In this example, it gets called only when the grid is first displayed and not when any item is highlighted/de-highlighted or selected/de-selected. 3) Yes, the styleFunction does get called when the highlighted object changes. But if you move the code to set data.highlighted there, you get the same result! It just seems like anything that changes this bound variable on every repaint of the cell is doomed to break the rollover highlight. On Tue, Jun 9, 2009 at 11:49 AM, Amy amyblankens...@... wrote: --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, Pan Troglodytes chimpathetic@ wrote: That was a good idea and it does get rid of the arraycollection walking. But I get the SAME problem with the grid losing highlighting when I did it using AdvancedGridItemRenderer, thought the symptoms are slightly different: Personally, I'd do one of two things: 1) Just look to see if the current item is the highlighted item in the styleFunction -or- 2) Override commitProperties instead of validateNow(). I'd also be tempted to investigate whether the styleFunction gets called when the highlighted object changes. HTH; Amy -- Jason
Re: [flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
When you set the highlighted property on your items, they are dispatching PropertyChangeEvents. The collection they are in will receive these PropertyChangeEvents and dispatch CollectionChangeEvents. The AdvancedDataGrid will receive these and perform a visual update, which appears to clear the rollover highlight. To prevent the rollover highlight clearing you need to avoid dispatching PropertyChangeEvents when you update the hightlighted property. Which means you need to use a custom event in your binding (see below). This should fix the choppiness without breaking the binding, although you might want to rethink this whole approach: When you select an item in a datagrid it sets the selectedItem property; it doesn't update the underlying data items. Why not follow this pattern for tracking which item is rolled over? package { import flash.events.EventDispatcher; public class TestObject extends EventDispatcher { [Bindable] public var label:String; private var _highlighted:Boolean; public function get highlighted() : Boolean { return _highlighted; } [Bindable( event = highlightedChange )] public function set highlighted( highlighted : Boolean ) : void { _highlighted = highlighted; dispatchEvent( new Event( highlightedChange ) ); } } } Pan Troglodytes wrote: 1) Yes, this works fine, for the display portion only. It doesn't address the actual problem of needing to set a flag in the data that indicates it is the currently highlighted one, that flag being also used by other things that bind to the data that don't want to know about UI details like the grid. In this case, I had a number of chart listeners that would toggle series on/off depending on which one was highlighted in the grid. 2) There is no commitProperties on AdvancedDataGridItemRenderer. Perhaps you meant validateProperties. In this example, it gets called only when the grid is first displayed and not when any item is highlighted/de-highlighted or selected/de-selected. 3) Yes, the styleFunction does get called when the highlighted object changes. But if you move the code to set data.highlighted there, you get the same result! It just seems like anything that changes this bound variable on every repaint of the cell is doomed to break the rollover highlight. On Tue, Jun 9, 2009 at 11:49 AM, Amy amyblankens...@bellsouth.net wrote: --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: That was a good idea and it does get rid of the arraycollection walking. But I get the SAME problem with the grid losing highlighting when I did it using AdvancedGridItemRenderer, thought the symptoms are slightly different: Personally, I'd do one of two things: 1) Just look to see if the current item is the highlighted item in the styleFunction -or- 2) Override commitProperties instead of validateNow(). I'd also be tempted to investigate whether the styleFunction gets called when the highlighted object changes. HTH; Amy
[flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
Nice Paul, So, extend ADG and add a highlightedItem:MyItemVO property that uses a Bindable highlightedChange event; with the same getter/setter structure as below. Not sure, in MyADG, if you'd set the highlightedItem on itemRollover or initialte from the itemRenderer, with an Event though; just depends on how you can get to the data or listData. But then change the exterior bindings to myADG.highlightedItem. Sound about right Paul. -TH --- In flexcoders@yahoogroups.com, Paul Williams p_m_willi...@... wrote: When you set the highlighted property on your items, they are dispatching PropertyChangeEvents. The collection they are in will receive these PropertyChangeEvents and dispatch CollectionChangeEvents. The AdvancedDataGrid will receive these and perform a visual update, which appears to clear the rollover highlight. To prevent the rollover highlight clearing you need to avoid dispatching PropertyChangeEvents when you update the hightlighted property. Which means you need to use a custom event in your binding (see below). This should fix the choppiness without breaking the binding, although you might want to rethink this whole approach: When you select an item in a datagrid it sets the selectedItem property; it doesn't update the underlying data items. Why not follow this pattern for tracking which item is rolled over? package { import flash.events.EventDispatcher; public class TestObject extends EventDispatcher { [Bindable] public var label:String; private var _highlighted:Boolean; public function get highlighted() : Boolean { return _highlighted; } [Bindable( event = highlightedChange )] public function set highlighted( highlighted : Boolean ) : void { _highlighted = highlighted; dispatchEvent( new Event( highlightedChange ) ); } } } Pan Troglodytes wrote: 1) Yes, this works fine, for the display portion only. It doesn't address the actual problem of needing to set a flag in the data that indicates it is the currently highlighted one, that flag being also used by other things that bind to the data that don't want to know about UI details like the grid. In this case, I had a number of chart listeners that would toggle series on/off depending on which one was highlighted in the grid. 2) There is no commitProperties on AdvancedDataGridItemRenderer. Perhaps you meant validateProperties. In this example, it gets called only when the grid is first displayed and not when any item is highlighted/de-highlighted or selected/de-selected. 3) Yes, the styleFunction does get called when the highlighted object changes. But if you move the code to set data.highlighted there, you get the same result! It just seems like anything that changes this bound variable on every repaint of the cell is doomed to break the rollover highlight. On Tue, Jun 9, 2009 at 11:49 AM, Amy amyblankens...@... wrote: --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, Pan Troglodytes chimpathetic@ wrote: That was a good idea and it does get rid of the arraycollection walking. But I get the SAME problem with the grid losing highlighting when I did it using AdvancedGridItemRenderer, thought the symptoms are slightly different: Personally, I'd do one of two things: 1) Just look to see if the current item is the highlighted item in the styleFunction -or- 2) Override commitProperties instead of validateNow(). I'd also be tempted to investigate whether the styleFunction gets called when the highlighted object changes. HTH; Amy
Re: [flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
That was a good idea and it does get rid of the arraycollection walking. But I get the SAME problem with the grid losing highlighting when I did it using AdvancedGridItemRenderer, thought the symptoms are slightly different: ?xml version=1.0 encoding=utf-8? Application xmlns=http://www.adobe.com/2006/mxml; creationComplete=cc() layout=horizontal Script ![CDATA[ import mx.events.ListEvent; import mx.collections.ArrayCollection; [Bindable] public var d:ArrayCollection = new ArrayCollection([]); private const ITEM_COUNT:int = 15; private function cc():void { for (var i:int = 0; i ITEM_COUNT; i++) { var item:TestObject = new TestObject; item.label = Item + i; d.addItem(item); } } private function getColStyle(data:Object, column:AdvancedDataGridColumn):Object { return { fontWeight:(data.highlighted ? bold : normal) } } ]] /Script AdvancedDataGrid id=list dataProvider={d} height=100% columns AdvancedDataGridColumn styleFunction=getColStyle dataField=label itemRenderer Component AdvancedDataGridItemRenderer Script ![CDATA[ import mx.controls.AdvancedDataGrid; override public function validateNow():void { var adg:AdvancedDataGrid = owner as AdvancedDataGrid; if (data adg) data.highlighted = adg.isItemHighlighted(data); super.validateNow(); } ]] /Script /AdvancedDataGridItemRenderer /Component /itemRenderer /AdvancedDataGridColumn /columns /AdvancedDataGrid /Application In this example, I don't loop through the dataprovider but instead only affect the itemRenderer being redrawn. Yet if you try this example with highlighted being a [Bindable] variable, it breaks, not just failing to show the highlighted item in bold but also breaking the grid's blue highlight. Comment out the [Bindable] part in TestObject, and it works just fine. I'm hoping Alex is still following along. I'm trying to get my itemRenderers in a big complicated grid as lean as possible, as per Alex's suggestions on his blog. The highlighted data is also being used in a couple of different places that are abstracted a bit, otherwise I'd hardcode something a bit more kludgy. On Fri, Jun 5, 2009 at 2:41 PM, Tim Hoff timh...@aol.com wrote: Hi Jason, Have you tried it from within the itemRenderer? Something like: * private * *var* adg : AdvancedDataGrid; *override* *public* *function* *set* data(value:Object):*void* { * super*.data = value; adg = owner *as* AdvancedDataGrid; } *override* *protected* *function* updateDisplayList( w:Number, h:Number ): *void *{ * super*.updateDisplayList( w, h ); data.highlighted = adg.isItemHighlighted(data); } Not sure if this will work for your purposes, but it's worth a shot. -TH --- In flexcoders@yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: Yes. A gigantic 15 items. ;) I wouldn't have thought going through a list of 15 items would be quite so processor intensive. Though even if it's just 5 items and I use Array instead of ArrayCollection, it's still choppy. The problem isn't so much that it's scanning through the entire collection, as if you change item.highlighted = list.isItemHighlighted(item) to trace('here');, the choppiness disappears. So, the problem is that it's setting this bound variable highlighted 15 times (or even just 5) for each item as it rolls over them. And the strange thing is that the data all gets set behind the scenes. What happens that the grid cells don't get repainted properly. If you actually play with the program a little, dragging your mouse around a bit, you'll see what I'm talking about. Here's a video that might be helpful: http://www.youtube.com/watch?v=7LQFlQtiHsc So it seems odd to me that the data is getting updated but the grid is losing track of the ability to highlight. You know what's really interesting? Change the style function this: private function getColStyle(data:Object, column:AdvancedDataGridColumn):Object { return { fontWeight:(data.highlighted ? bold : normal) } } Now you'll see that the bolding tracks perfectly! The reason it failed before was the same reason the blue mouseover highlight was failing. Internally, the grid is losing the ability to highlight. On Thu, Jun 4, 2009 at 11:28 PM, Alex Harui aha...@... wrote: The rollover handler is scanning the entire arraycollection. Alex Harui Flex SDK Developer Adobe Systems Inc. http://www.adobe.com/ Blog: http://blogs.adobe.com/aharui *From:* flexcoders@yahoogroups.com
Re: [flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
Oh yeah, another thing I should point out is that in the real grid, I have multiple columns. As such, a solution that relies on the itemRenderer might be problematic due to gaps between items and such. I would just use the itemRollOver and itemRollOut to do it all, but rollOut doesn't get reliably called for every highlighted row when the highlight leaves it. On Mon, Jun 8, 2009 at 3:46 PM, Pan Troglodytes chimpathe...@gmail.comwrote: That was a good idea and it does get rid of the arraycollection walking. But I get the SAME problem with the grid losing highlighting when I did it using AdvancedGridItemRenderer, thought the symptoms are slightly different: ?xml version=1.0 encoding=utf-8? Application xmlns=http://www.adobe.com/2006/mxml; creationComplete=cc() layout=horizontal Script ![CDATA[ import mx.events.ListEvent; import mx.collections.ArrayCollection; [Bindable] public var d:ArrayCollection = new ArrayCollection([]); private const ITEM_COUNT:int = 15; private function cc():void { for (var i:int = 0; i ITEM_COUNT; i++) { var item:TestObject = new TestObject; item.label = Item + i; d.addItem(item); } } private function getColStyle(data:Object, column:AdvancedDataGridColumn):Object { return { fontWeight:(data.highlighted ? bold : normal) } } ]] /Script AdvancedDataGrid id=list dataProvider={d} height=100% columns AdvancedDataGridColumn styleFunction=getColStyle dataField=label itemRenderer Component AdvancedDataGridItemRenderer Script ![CDATA[ import mx.controls.AdvancedDataGrid; override public function validateNow():void { var adg:AdvancedDataGrid = owner as AdvancedDataGrid; if (data adg) data.highlighted = adg.isItemHighlighted(data); super.validateNow(); } ]] /Script /AdvancedDataGridItemRenderer /Component /itemRenderer /AdvancedDataGridColumn /columns /AdvancedDataGrid /Application In this example, I don't loop through the dataprovider but instead only affect the itemRenderer being redrawn. Yet if you try this example with highlighted being a [Bindable] variable, it breaks, not just failing to show the highlighted item in bold but also breaking the grid's blue highlight. Comment out the [Bindable] part in TestObject, and it works just fine. I'm hoping Alex is still following along. I'm trying to get my itemRenderers in a big complicated grid as lean as possible, as per Alex's suggestions on his blog. The highlighted data is also being used in a couple of different places that are abstracted a bit, otherwise I'd hardcode something a bit more kludgy. On Fri, Jun 5, 2009 at 2:41 PM, Tim Hoff timh...@aol.com wrote: Hi Jason, Have you tried it from within the itemRenderer? Something like: * private * *var* adg : AdvancedDataGrid; *override* *public* *function* *set* data(value:Object):*void* { * super*.data = value; adg = owner *as* AdvancedDataGrid; } *override* *protected* *function* updateDisplayList( w:Number, h:Number ):*void *{ * super*.updateDisplayList( w, h ); data.highlighted = adg.isItemHighlighted(data); } Not sure if this will work for your purposes, but it's worth a shot. -TH --- In flexcoders@yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: Yes. A gigantic 15 items. ;) I wouldn't have thought going through a list of 15 items would be quite so processor intensive. Though even if it's just 5 items and I use Array instead of ArrayCollection, it's still choppy. The problem isn't so much that it's scanning through the entire collection, as if you change item.highlighted = list.isItemHighlighted(item) to trace('here');, the choppiness disappears. So, the problem is that it's setting this bound variable highlighted 15 times (or even just 5) for each item as it rolls over them. And the strange thing is that the data all gets set behind the scenes. What happens that the grid cells don't get repainted properly. If you actually play with the program a little, dragging your mouse around a bit, you'll see what I'm talking about. Here's a video that might be helpful: http://www.youtube.com/watch?v=7LQFlQtiHsc So it seems odd to me that the data is getting updated but the grid is losing track of the ability to highlight. You know what's really interesting? Change the style function this: private function getColStyle(data:Object, column:AdvancedDataGridColumn):Object { return { fontWeight:(data.highlighted ? bold : normal) } } Now you'll see that the
[flexcoders] Re: how to fix poor performance in this example (AdvancedDataGrid and Binding)
Hi Jason, Have you tried it from within the itemRenderer? Something like: private var adg : AdvancedDataGrid; override public function set data(value:Object):void { super.data = value; adg = owner as AdvancedDataGrid; } override protected function updateDisplayList( w:Number, h:Number ):void { super.updateDisplayList( w, h ); data.highlighted = adg.isItemHighlighted(data); } Not sure if this will work for your purposes, but it's worth a shot. -TH --- In flexcoders@yahoogroups.com, Pan Troglodytes chimpathe...@... wrote: Yes. A gigantic 15 items. ;) I wouldn't have thought going through a list of 15 items would be quite so processor intensive. Though even if it's just 5 items and I use Array instead of ArrayCollection, it's still choppy. The problem isn't so much that it's scanning through the entire collection, as if you change item.highlighted = list.isItemHighlighted(item) to trace('here');, the choppiness disappears. So, the problem is that it's setting this bound variable highlighted 15 times (or even just 5) for each item as it rolls over them. And the strange thing is that the data all gets set behind the scenes. What happens that the grid cells don't get repainted properly. If you actually play with the program a little, dragging your mouse around a bit, you'll see what I'm talking about. Here's a video that might be helpful: http://www.youtube.com/watch?v=7LQFlQtiHsc So it seems odd to me that the data is getting updated but the grid is losing track of the ability to highlight. You know what's really interesting? Change the style function this: private function getColStyle(data:Object, column:AdvancedDataGridColumn):Object { return { fontWeight:(data.highlighted ? bold : normal) } } Now you'll see that the bolding tracks perfectly! The reason it failed before was the same reason the blue mouseover highlight was failing. Internally, the grid is losing the ability to highlight. On Thu, Jun 4, 2009 at 11:28 PM, Alex Harui aha...@... wrote: The rollover handler is scanning the entire arraycollection. Alex Harui Flex SDK Developer Adobe Systems Inc. http://www.adobe.com/ Blog: http://blogs.adobe.com/aharui *From:* flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] *On Behalf Of *Pan Troglodytes *Sent:* Thursday, June 04, 2009 12:00 PM *To:* flexcoders *Subject:* [flexcoders] how to fix poor performance in this example (AdvancedDataGrid and Binding) I have the following example that is a very simplified form of what I need to do in my much larger program. The goal is to have a mouseover on a grid item set a variable in the data object. In the real program, this fires off some other code which makes that item visible and the others hidden, etc. But here, I'm just trying the first part. *TestObject.as:* package { public class TestObject { [Bindable] public var label:String; [Bindable] public var highlighted:Boolean; } } *GenericTest.mxml: *?xml version=1.0 encoding=utf-8? Application xmlns=http://www.adobe.com/2006/mxml; creationComplete=cc() layout=horizontal Script ![CDATA[ import mx.events.ListEvent; import mx.collections.ArrayCollection; [Bindable] public var d:ArrayCollection = new ArrayCollection([]); private const ITEM_COUNT:int = 15; private function cc():void { for (var i:int = 0; i ITEM_COUNT; i++) { var item:TestObject = new TestObject; item.label = Item + i; d.addItem(item); } } private function listRollover(e:ListEvent):void { for each (var item:TestObject in d) item.highlighted = list.isItemHighlighted(item); } private function getColStyle(data:Object, column:AdvancedDataGridColumn):Object { return { fontWeight:(list.isItemHighlighted(data) ? bold : normal) } } private function getColStyle2(data:Object, column:AdvancedDataGridColumn):Object { return { fontWeight:(list2.isItemHighlighted(data) ? bold : normal) } } ]] /Script AdvancedDataGrid id=list dataProvider={d} height=100% itemRollOver=listRollover(event) columns AdvancedDataGridColumn styleFunction=getColStyle dataField=label/ /columns /AdvancedDataGrid AdvancedDataGrid id=list2 dataProvider={d} height=100% columns AdvancedDataGridColumn styleFunction=getColStyle2 dataField=label/ /columns /AdvancedDataGrid /Application To see the problem, run your mouse up and down the list on the left and the list on the right. If you get the same results I do with SDK 3.0.2 and player 10,0,12,36 (FF 3.0.6 or IE 7), you'll see that the list on the right tracks very smoothly but the one on the left is choppy. The only difference between the two is that the one on the left has a rollOver handler that sets a Bindable variable in the data object. If you comment out the [Bindable] on TestObject's highlighted variable, the choppiness goes away.