CellRendererCheckbox

Package:
Class:
Inheritance:
biz.flashscript.cellrenderer
public class CellRendererCheckbox
CheckBox
The CellRendererCheckbox class is used to add CheckBox instances to a datagrid component. Pressing the checkboxes will check one item.
Public Properties
Property Defined By
data : Object
Interface method.
ICellRenderer
listData : ListData
Interface method
ICellRenderer
Public Methods
Method Defined By
CellRendererCheckbox()
Creates a new instance of the CellRendererCheckbox component.
CellRendererCheckbox
Property Detail
data property
data:Object [read-write]

Method is Interface method of ICellRenderer.

Implementation

public function get data():Object
public function set data(value:Object):void

listData property
listData:ListData [read-write]

Method is Interface method of ICellRenderer.

Implementation

public function get listData():ListData
public function set listData(value:ListData):void
Constructor Detail
CellRendererCheckbox ()  Constructor
public function CellRendererCheckbox()
Intializes a new CellRendererCheckbox instance.
Examples
Create a fla file and name it GridCheckbox_1.fla. Place a datagrid anc checkbox component in the library. Create a new Actionscript 3 file and name it GridCheckbox_1.as. Place the script below in the file.
package 
{
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import fl.controls.DataGrid;
	import fl.controls.dataGridClasses.DataGridColumn;
	import fl.data.DataProvider;
	import flash.events.*;
	import biz.flashscript.cellrenderer.CellRendererCheckbox;
	/*
	* This class extends an Abstractclass, which we need for communication.
	*/
	public class GridCheckbox_1 extends Sprite
	{
		private var itemArray:Array = new Array  ;

		public function GridCheckbox_1 ():void
		{
			/*
			* We add a new DataGrid and set its properties.
			*/
			var myGrid:DataGrid = new DataGrid  ;
			myGrid.name = "Datagrid";
			myGrid.move (35,80);
			myGrid.setSize (350,125);
			addChild (myGrid);
			/*
			* We add 4 columns here and define their properties. The text in the columns
			* represents the variables for the array.
			*/
			var _no:DataGridColumn = new DataGridColumn("no");
			var _item:DataGridColumn = new DataGridColumn("item");
			var _price:DataGridColumn = new DataGridColumn("price");
			var _check:DataGridColumn = new DataGridColumn("data");
			/*
			* In the _check column we want to load the CheckBox instances. So we create a 
			* cellrenderer for this column.
			*/
			CellRendererCheckbox.myLabel = "Check to buy";
			_check.cellRenderer = CellRendererCheckbox;
			/*
			* we add the columns to the grid.
			*/
			myGrid.addColumn (_no);
			myGrid.addColumn (_item);
			myGrid.addColumn (_price);
			myGrid.addColumn (_check);
			/*
			* we set heights and widths of the columns and add header text for each column.
			*/
			myGrid.rowHeight = 25;
			_no.width = 50;
			_item.width = 100;
			_price.width = 75;
			_check.width = 125;
			_no.headerText = "Num";
			_item.headerText = "Item Description";
			_price.headerText = "Price";
			_check.headerText = "Check to buy";
			/*
			* We fill the DataGrid with data. To add the CheckBox we use MyIcon" as
			* for the data variable. That will be the data value, which we use to 
			* identify the library symbol.
			*/
			var dp:DataProvider = new DataProvider();
			dp.addItem ({no:"1",item:"Apples",price:"$1,50",data:"selected"});
			dp.addItem ({no:"2",item:"Oranges",price:"$0.89",data:"selected"});
			dp.addItem ({no:"3",item:"Banana",price:"$0.59",data:"selected"});
			dp.addItem ({no:"4",item:"Cherries",price:"$2.69",data:"selected"});
			myGrid.dataProvider = dp;
			myGrid.addEventListener (MouseEvent.CLICK,changeHandler);
		}
		/*
		* This is the listener when the DataGrid rows have been selected.
		*/
		private function changeHandler (event:Event):void
		{
			var myGrid:DataGrid = event.currentTarget as DataGrid;
			trace (myGrid.selectedItem.item);
		}
	}
}
Get Adobe Flash player