1 Reply Latest reply on Sep 28, 2011 11:09 PM by flcs4

    typeerror #1009 drawcolumnbackground() in advanceddatagridbaseex.as:3966


      I have implemented an extension to the advanced datagrid class that would read its column design through a web service call, would then dynamically add the advanced columns as required and when ready with that, read the grid data again through a web service call. In a final step the in memory data grid object would be added to a UI container.


      Somewhere after assigning the dataprovider and the following adding of the grid to the UI container, a rendering event takes place that would try to display the column backgrounds before the internal data structure has been created (through setting the dataprovider).


      The drawcolumnbackground() method is referencing row information that isn't available at this point and hence the error exception.


      The following code is taken out from the current advanceddatagridbaseex.as (SDK 4.5.1)


          protected function drawColumnBackground(s:Sprite, columnIndex:int,

                                                   color:uint, column:AdvancedDataGridColumn):void


               var background:Shape;

               background = Shape(s.getChildByName(columnIndex.toString()));


               if (!background)


                   background = new FlexShape();


                   background.name = columnIndex.toString();



               var g:Graphics = background.graphics;




               if(columnIndex >= lockedColumnCount &&

                  columnIndex < lockedColumnCount + horizontalScrollPosition)





               var lastRow:Object = rowInfo[listItems.length - 1];

               var headerInfo:AdvancedDataGridHeaderInfo = getHeaderInfo(getOptimumColumns()[columnIndex]);

               var xx:Number = headerInfo.headerItem.x;


               if(columnIndex >= lockedColumnCount)

                   xx = getAdjustedXPos(xx);


               var yy:Number = headerRowInfo[0].y;


                if (headerVisible)

                   yy += headerRowInfo[0].height;


                // Height is usually as tall is the items in the row, but not if

               // it would extend below the bottom of listContent

               var height:Number = Math.min(lastRow.y + lastRow.height,

                                            listContent.height - yy);


               g.drawRect(xx, yy, headerInfo.headerItem.width,

                          listContent.height - yy);





      The line numbers above in bold red are the culprits. There are two aspects to this problem:


      1) The rendering event takes place at the wrong point in time


      2) The two line numbers are redundent. They effectively do nothing, except for throwing an error.


      I have solved the problem by writing my own FdnAdvancedDataGrid class extending the AdvancedDateGrid class simply overriding the function drawcolumnbackground()...


      package packages.FdnClasses


          import mx.controls.AdvancedDataGrid;

          import flash.display.Sprite;   

          import mx.controls.AdvancedDataGridBaseEx;

          import mx.controls.advancedDataGridClasses.AdvancedDataGridBase;

          import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;



          public class FdnAdvancedDateGrid extends AdvancedDataGrid


              public function FdnAdvancedDateGrid()





              override protected function drawColumnBackground(s:Sprite, columnIndex:int,

                                                               color:uint, column:AdvancedDataGridColumn):void


                  if (this.rowInfo.length==0) return;

                  if (this.listItems.length==0) return;


                  var lastRow:Object = rowInfo[listItems.length - 1];   


                  if (lastRow) super.drawColumnBackground(s, columnIndex,    color, column);