CustomCellRenderer

Package:
Class:
Inheritance:
biz.flashscript.cellrenderer
public class CustomCellRenderer
CellRenderer
The CustomCellRenderer class allows changing properties of the DataGrid component except header. Use the method CustomCellRenderer() to create an instance of the class.
Public Properties
Property Defined By
mulLine : Boolean
Specifies multiline property.
CustomCellRenderer
wordRap : Boolean
Specifies wordwrap property.
CustomCellRenderer
forFont : String
Specifies the font in the header.
CustomCellRenderer
embFont : Font
Specifies the font class when embedded.
CustomCellRenderer
fntSize : int
Specifies the font size.
CustomCellRenderer
fntColor : uint
Specifies the font color.
CustomCellRenderer
auSize : String
Specifies the text location.
CustomCellRenderer
Public Methods
Method Defined By
CustomCellRenderer()
Creates a new instance of the CustomCellRenderer class.
CustomCellRenderer
Property Detail
mulLine property
mulLine:Boolean=false [read-write]

Specifies multiline of textfield. Default is false.

Implementation

public static var mulLine:Boolean=false
wordRap property
wordRap:Boolean=false [read-write]

Specifies the wordwrap. Default is false.

Implementation

public static var wordRap:Boolean=false
forFont property
forFont:String="Verdana"; [read-write]

Specifies the font. Default is "Verdana".

Implementation

public static var forFont:String="Verdana";
embFont property
embFont:Font [read-write]

Optional: Specifies the Font class when embedded.

Implementation

public static var embFont:uint
fntSize property
fntSize:int=12 [read-write]

Specifies the font size. Default is 12.

Implementation

public static var fntSize:int=12
fntColor property
fntColor:uint=0x000000 [read-write]

Specifies the font color color. Default is 0x000000.

Implementation

public static var fntColor:uint=0x000000
auSize property
auSize:String="center" [read-write]

Specifies the location of the text. Default is "center" ("right","left").

Implementation

public static var auSize:String="center"
Constructor Detail
CustomCellRenderer ()  Constructor
public function CustomCellRenderer()
To initialize an instance use the setStyle method.
Event Detail
N/A
Examples
EXAMPLE: Create a new fla file and name it CustomRendererExample.fla. Place the fla in the same folder as the biz folder. Place a datagrid component (myGrid), one button component (myBut), one textinput component (myInput), and one combobox component (mySize). Then create an Actionscript file, name it CustomRendererExample.as and place this script.
package 
{
	import flash.display.Sprite;
	import flash.events.*;
	import fl.controls.DataGrid;
	import fl.controls.Button;
	import fl.controls.TextInput;
	import fl.controls.ComboBox;
	import fl.controls.dataGridClasses.DataGridColumn;
	import fl.controls.dataGridClasses.DataGridCellEditor;
	import biz.flashscript.cellrenderer.CustomCellRenderer;
	import biz.flashscript.cellrenderer.CustomCellRenderer;
	import flash.text.Font;

	public class CustomRendererExample extends Sprite
	{
		public var myGrid:DataGrid;
		private var myName:DataGridColumn;
		public var myBut:Button;
		public var myInput:TextInput;
		public var mySize:ComboBox;
		private var sSize:String;
		private var restrictSize:String = "1";
		
		public function CustomRendererExample ():void
		{
			myInput.text = "ENTER....";
			myInput.addEventListener (FocusEvent.FOCUS_IN, whenFocus);
			myInput.addEventListener(Event.CHANGE, inputHandler);

			var myFont:Font = new BritannicBold();
			CustomCellRenderer.embFont = myFont;
			CustomCellRenderer.fntColor = 0xFF0000;
			myGrid.setStyle ("cellRenderer",CustomCellRenderer);
			myGrid.setSize (200,300);
			
			CustomCellRenderer.embFont = myFont;
			CustomCellRenderer.fntColor = 0xFFFFFF;
			myGrid.setStyle ("headerRenderer",CustomCellRenderer);
			
			myName = new DataGridColumn();
			var _size:DataGridColumn = new DataGridColumn();
			myGrid.columns = ["myName","_size"];
			myGrid.getColumnAt(0).width = 140;
			myGrid.getColumnAt(0).headerText = "Name (case sensitive)";
			myGrid.getColumnAt(1).width = 60;
			myGrid.getColumnAt(1).headerText = "Size";
			myGrid.getColumnAt(1).editable = true;
			myGrid.addEventListener (Event.CHANGE, changeHandler);
			myBut.label = "Add item";
			myBut.addEventListener(MouseEvent.CLICK, cHandler);
			mySize.addItem({label:"xs"});
			mySize.addItem({label:"s"});
			mySize.addItem({label:"m"});
			mySize.addItem({label:"l"});
			mySize.addItem({label:"xl"});
			mySize.addItem({label:"xxl"});
			mySize.addEventListener(Event.CHANGE, sizeHandler);
			sSize = "xs";
		}
		private function changeHandler (event:Event):void
		{
			myGrid.removeItemAt(myGrid.selectedIndex);
		}
		private function cHandler (event:Event):void
		{
			myGrid.addItem ({myName:myInput.text, _size:sSize});
			myInput.text = "";
			myInput.setFocus();
		}
		private function sizeHandler (event:Event):void
		{
			sSize = event.currentTarget.selectedItem.label;
		}
		private function inputHandler(event:Event):void
		{
			var ip:TextInput = event.currentTarget as TextInput;
			switch(restrictSize)
			{
				case "1":
				if (ip.text.length > 14)
				{
					ip.maxChars = 15;
				}
				break;
				case "2":
				if (ip.text.length > 11)
				{
					ip.maxChars = 12;
				}
				break;
				case "3":
				if (ip.text.length > 6)
				{
					ip.maxChars = 7;
				}
				break;
			}
		}
		private function whenFocus (event:FocusEvent):void
		{
			if (event.currentTarget.text != "")
			{
				event.currentTarget.text = "";
			}
		}
	}
}