1 Reply Latest reply on Oct 7, 2010 12:21 PM by damonfarr

    Datagrid crashes on scroll

    damonfarr

      When using a custom cell renderer and variable row height the data grid crashes when scrolling. In order to recreate this problem the last two elements in the data grid must be the default row height, and I must be using the item renderer. I am using Firefox 3.6.10 and flash 10.1. Below is the code for my item renderer:

       

      package com.epsWay.view.renderers.dataGrid
      {
          import com.epsWay.control.events.ReportEvent;
          import com.epsWay.model.Report;
          import com.epsWay.model.User;
         
          import flash.events.MouseEvent;
         
          import mx.controls.*;
          import mx.core.*;
          import mx.styles.StyleManager;
          import mx.utils.ObjectUtil;

       

          public class TrashCan extends Button
          {
              protected var report:Report;
             
              public function TrashCan()
              {
                  super();
                  width = 20;
                  height = 20;
              }
             
              override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ):void
              {
                  super.updateDisplayList( 20, 20 );
                  width = 20;
                  height = 20;
                  if( StyleManager.getStyleDeclaration(".trashCan") != null ){
                      setStyle("upSkin", StyleManager.getStyleDeclaration(".trashCan").getStyle("upSkin") );
                      setStyle("overSkin", StyleManager.getStyleDeclaration(".trashCan").getStyle("overSkin") );
                      setStyle("downSkin", StyleManager.getStyleDeclaration(".trashCan").getStyle("downSkin") );
                      setStyle("disabledSkin", StyleManager.getStyleDeclaration(".trashCan").getStyle("disabledSkin") );
                  }
                  x += ( unscaledWidth - width )/2;
              }
             
              override public function set data( value:Object ):void
              {
                  super.data = value;
                 if (value != null && value.report is Report )
                  {
                      report = Report( value.report );
                      addEventListener(MouseEvent.CLICK, onButtonClick );
                  }

       

                  super.invalidateDisplayList();
              }
             
              protected function onButtonClick( event:MouseEvent ):void{
                  if( report != null ){
                      //dispatch delete report event
                      var reportEvent:ReportEvent = new ReportEvent( ReportEvent.TRASH_CAN_CLICK, new User(), report, null, null, null, null, true );
                      dispatchEvent( reportEvent );
                  }
              }
             
          }
      }

        • 1. Re: Datagrid crashes on scroll
          damonfarr Level 1

          So I was able to solve this issue. It was my fault. I re-examined the cell renderer and realized I was doing some pretty crazy things. Re-adjusted as follows and works perfect:

           

          package com.epsWay.view.renderers.dataGrid
          {
              import com.epsWay.control.events.ReportEvent;
              import com.epsWay.model.Report;
              import com.epsWay.model.User;
             
              import flash.events.MouseEvent;
             
              import mx.containers.Canvas;
              import mx.controls.*;
              import mx.core.*;
              import mx.styles.StyleManager;

           

              public class TrashCan extends Canvas
              {
                  protected var report:Report;
                  protected var button:Button = new Button();
                 
                  public function TrashCan()
                  {
                      super();
                  }
                 
                  override protected function createChildren():void
                  {
                      super.createChildren();
                      if( StyleManager.getStyleDeclaration(".trashCan") != null ){
                          button.setStyle("upSkin", StyleManager.getStyleDeclaration(".trashCan").getStyle("upSkin") );
                          button.setStyle("overSkin", StyleManager.getStyleDeclaration(".trashCan").getStyle("overSkin") );
                          button.setStyle("downSkin", StyleManager.getStyleDeclaration(".trashCan").getStyle("downSkin") );
                          button.setStyle("disabledSkin", StyleManager.getStyleDeclaration(".trashCan").getStyle("disabledSkin") );
                      }
                      button.width = 20;
                      button.height = 20;
                      addChild( button );
                  }
                 
                  override protected function updateDisplayList( unscaledWidth:Number, unscaledHeight:Number ):void
                  {
                      super.updateDisplayList( unscaledWidth, unscaledHeight );
                      button.x = ( unscaledWidth - 20 )/2;
                      button.y = ( unscaledHeight - 20 )/2;
                  }
                 
                  override public function set data( value:Object ):void
                  {
                      super.data = value;
                     if (value != null && value.report is Report )
                      {
                          report = Report( value.report );
                          button.addEventListener(MouseEvent.CLICK, onButtonClick );
                      }

           

                      super.invalidateDisplayList();
                  }
                 
                  protected function onButtonClick( event:MouseEvent ):void{
                      if( report != null ){
                          //dispatch delete report event
                          var reportEvent:ReportEvent = new ReportEvent( ReportEvent.TRASH_CAN_CLICK, new User(), report, null, null, null, null, true );
                          dispatchEvent( reportEvent );
                      }
                  }
                 
              }
          }