| Package | qnx.ui.listClasses |
| Class | public class AlternatingCellRenderer |
| Inheritance | AlternatingCellRenderer CellRenderer SkinnableComponent UIComponent flash.display.MovieClip |
AlternatingCellRenderer class is the default cell renderer for the List class.
As the name suggests, AlternatingCellRenderer renders the cells in the list using alternating row colors, such that
each adjacent row uses a different color.
See also
| Method | Defined By | ||
|---|---|---|---|
Creates a new AlternatingCellRenderer instance. | AlternatingCellRenderer | ||
![]() | destroy():void
Call this method when you want to have your object collected by the garbage collector. | UIComponent | |
![]() | drawNow():void
Calls the draw() method. | UIComponent | |
![]() | getTextFormatForState(state:String):TextFormat
Returns the TextFormat object for a specified state. | CellRenderer | |
![]() | invalidate(property:String, invalidateNow:Boolean = false):void
Marks the property as invalid and the draw() method is called on the next frame or the next render, whichever comes first. | UIComponent | |
![]() | setPosition(x:Number, y:Number):void
Sets the x and y position of the component. | UIComponent | |
![]() | setSize(w:Number, h:Number):void [override]
Sets the width and height of the component. | CellRenderer | |
![]() | setSkin(cellSkin:Object):void
Set the skin object on the component for it to render. | SkinnableComponent | |
![]() | setTextFormatForState(format:TextFormat, state:String):void
Sets the TextFormat object for the label of a given state. | CellRenderer | |
| AlternatingCellRenderer | () | Constructor |
public function AlternatingCellRenderer()
Creates a new AlternatingCellRenderer instance.
In the following example, a custom AlternatingCellRenderer class is created in order to place a check box component
inside of each cell. The AlternatingCellRenderer is used to display grocery items. The class contains event listeners
to provide custom processing for mouse click events.
package
{
import flash.events.Event;
import flash.events.MouseEvent;
import qnx.ui.buttons.CheckBox;
import qnx.ui.listClasses.AlternatingCellRenderer;
public class MyCustomCellRenderer extends AlternatingCellRenderer
{
private var myCB:CheckBox;
public function MyCustomCellRenderer()
{
}
override protected function init():void
{
super.init();
myCB = new CheckBox();
myCB.x = 250;
myCB.y = 10;
this.addChild(myCB);
myCB.addEventListener( MouseEvent.CLICK, onClick );
//add this listener in order to block the mouse down event from the list
//see the onMouseDown method to see how to stop the event propagation
myCB.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown);
}
//this will prevent the cell from being selected when the button is clicked down
private function onMouseDown(event:MouseEvent):void
{
event.stopImmediatePropagation();
}
private function onClick(event:MouseEvent):void
{
dispatchEvent( new Event( Event.SELECT, true, true ) );
}
}
}
The following sample application calls the custom AlternatingCellRenderer class that is listed above.
package
{
import flash.display.Sprite;
import qnx.ui.data.DataProvider;
import qnx.ui.listClasses.List;
import qnx.ui.listClasses.ListSelectionMode;
[SWF(height="600", width="1024",
frameRate="30", backgroundColor="#FFFFFF")]
public class CustomListSample extends Sprite
{
public function CustomListSample()
{
initializeUI();
}
private function initializeUI():void
{
var arrItems:Array=[];
arrItems.push({label: "Apples"});
arrItems.push({label: "Potatoes"});
arrItems.push({label: "Oranges"});
arrItems.push({label: "Tomatoes"});
arrItems.push({label: "Carrots"});
arrItems.push({label: "Eggplant"});
arrItems.push({label: "Celery"});
arrItems.push({label: "Milk"});
arrItems.push({label: "Ham"});
arrItems.push({label: "Cheese"});
arrItems.push({label: "Bacon"});
var myList:List = new List();
myList.setPosition(100, 200);
myList.width = 300;
myList.height = 300;
myList.selectionMode = ListSelectionMode.MULTIPLE;
myList.dataProvider = new DataProvider(arrItems);
myList.setSkin(MyCustomCellRenderer);
this.addChild(myList);
}
}
}