title: ActionScript - Access List/DataProvider From Custom CellRenderer
body: <p>the code below sets up a List object in the main controller class that uses a custom cell renderer (CustomListCell class).  the CustomListCell class creates a Button object for the cell that will be used to delete itself from the List's DataProvider.</p>
  
  <p>how can i properly access the parent List object from its custom cell renderer?</p>
  
  <pre><code>//Controller Class
  private function createList():void
   {
   provider = new DataProvider(data);
  
   list = new List();
   list.width = 200;
   list.height = 400;
   list.rowHeight = 50;
   list.dataProvider = provider;
   list.setStyle("cellRenderer", CustomListCell);
   }
  
  -----
  
  //CustomListCell Class
  import fl.controls.Button;
  
  public class CustomListCell extends Sprite implements ICellRenderer
   {     
   public function CustomListCell()
    {
    var button:Button = new Button();
    button.label = "Delete Cell";
    button.addEventListener(MouseEvent_MOUSE_DOWN, deleteCellHandler);
          addChild(button);
    }
  
   private function deleteCellHandler(evt:MouseEvent):void
    {
    //Access List/DataProvider Here
    }
  
   //required implemented ICellRenderer functions follow
   }
  </code></pre>
  
  <hr>
  
  <h2>UPDATE</h2>
  
  <p>the following is my working custom renderer that implements ICellRenderer with Flash v3 List component.  the List's dataProvider consists of 2 elements for each cell:  randomColor and randomNumber.</p>
  
  <pre><code>package
  {
  //Imports
  import fl.controls.Button;
  import fl.controls.List;
  import fl.controls.listClasses.ICellRenderer; 
  import fl.controls.listClasses.ListData;
  import flash.display.Sprite;
  import flash.events.MouseEvent;
  import flash.text.TextField;
  import flash.text.TextFieldAutoSize;
  import flash.geom.ColorTransform;
  
  //Class
  public class TouchListRenderer extends Sprite implements ICellRenderer
      {
      //Properties
      private var cellWidthProperty:Number;
      private var cellHeightProperty:Number;
      private var dataProperty:Object;
      private var listDataProperty:ListData;  
      private var selectedProperty:Boolean;
  
      //Cell Display Objects
      private var backgroundCanvas:MySprite = new MySprite();
      private var numberTextField:TextField = new TextField();
      private var button:Button = new Button();
  
      //Constructor
      public function TouchListRenderer()
          {
          }
  
      //Size Setter (Getter Functions Intentionally Omitted)
      public function setSize(width:Number, height:Number):void
          {
          cellWidthProperty = width;
          cellHeightProperty = height;
          }
  
      //Data Setter
      public function set data(value:Object):void
          {
          dataProperty = value;
          }
  
      //Data Getter
      public function get data():Object
          { 
          return dataProperty; 
          }
  
      //List Data Setter
      public function set listData(value:ListData):void
          { 
          listDataProperty = value;
          }
  
      //List Data Getter
      public function get listData():ListData
          { 
          return listDataProperty; 
          }
  
      //Selected Setter
      public function set selected(value:Boolean):void
          { 
          selectedProperty = value;
  
          layout();
          }
  
      //Selected Getter
      public function get selected():Boolean
          { 
          return selectedProperty;
          }
  
      //Size And Layout
      private function layout():void
          {
          var newColor:ColorTransform = new ColorTransform();
          newColor.color = dataProperty.randomColor;
  
          backgroundCanvas.transform.colorTransform = newColor;
          backgroundCanvas.scaleX = cellWidthProperty / backgroundCanvas.width;
          backgroundCanvas.scaleY = cellHeightProperty / backgroundCanvas.height;
  
          numberTextField.text = dataProperty.randomNumber;
          numberTextField.autoSize = TextFieldAutoSize.LEFT;
          numberTextField.textColor = 0xFFFFFF;
          numberTextField.x = 50;
          numberTextField.y = cellHeightProperty / 2 - numberTextField.height / 2;
          numberTextField.border = true;
          numberTextField.selectable = false;
  
          button.label = "Delete";
          button.x = cellWidthProperty - button.width - 50;
          button.y = cellHeightProperty / 2 - button.height / 2;
          button.drawNow();
          button.addEventListener(MouseEvent.MOUSE_DOWN, buttonClickEventHandler);
  
          addChild(backgroundCanvas);
          addChild(numberTextField);
          addChild(button);
          }
  
      //Button Click Event Handler
      private function buttonClickEventHandler(evt:MouseEvent):void
          {
          List(listDataProperty.owner).removeItemAt(listDataProperty.index);
          }
  
      //Style Setter
      public function setStyle(style:String, value:Object):void
          {
          }
  
      //Mouse State Setter
      public function setMouseState(state:String):void
          {
          }
      } 
  } 
  </code></pre>
  
  <hr>
  
  <pre><code>package
  {
  import flash.display.Sprite;
  
  public class MySprite extends Sprite
      {
      public function MySprite()
          {
          graphics.beginFill(0xFF0000);
          graphics.drawRect(0, 0, 10, 10);
          graphics.endFill();
          }
      }
  }
  </code></pre>