Skip to content
bustardcelly edited this page Oct 25, 2010 · 6 revisions

Picker is a composite control of multiple ScrollList instances allowing for selection of values across multiple models. Te dataProvider for a Picker control is a Vector of PickerColumn instances.

PickerColumn

PickerColumn is a model representing the data provided to a single ScrollList within a Picker control. The following are the properties available on PickerColumn

+ itemRenderer:String
A fully-qualified class name of an IScrollListRenderer implementation that knows how to render an item of specified data.

+ data:Array
An Array of data objects that the tagret item renderer instance knows how to handle.

+ layout:IScrollListVerticalLayout
An IScrollListVerticalLayout implementation that lays out the item renderers along the y-axis within a ScrollList

+ width:Number
The optional width to set a single associated ScrollList. If not set, the Picker control will determine the available width percentage and base the associated ScrollList on that value.

Picker

To fill the Picker control with ScrollList instances, a list of PickerColumn is handed to its dataProvider. The Picker control will than handle the creation and instantiation of each associated ScrollList with a PickerColumn and its attributes.

The following is an exmaple of using a Picker control as a Date Chooser:

Example:

var dataProvider:Vector.<PickerColumn> = new Vector.<PickerColumn>();
dataProvider.push( getPickerColumnMonths() );
dataProvider.push( getPickerColumnDays( 50 ) );
dataProvider.push( getPickerColumnYears( 80 ) );
picker = new Picker();
picker.itemHeight = 50;
picker.dataProvider = dataProvider;
addChild( picker );

Because the selection display bar of a Picker is used to denote a selected item from a list, the itemHeight property is set uniformy on each ScrollList instance to properly display selection.

Changes to selection within the Picker control can be handled by registering with the selectionChange Signal. The following is the method signature for the selectionChange accessor:

/**
* Returns the signal reference for selection change. 
* @return Signal Signal( PickerColumn, int )
*/
public function get selectionChange():Signal;

Any handle registering with selectionChange must declare the PickerColumn and int arguments. The PickerColumn relates to the column model that has changed its selection, and the int is the index selection within that model.

Example:

var dataProvider:Vector.<PickerColumn> = new Vector.<PickerColumn>();
dataProvider.push( getPickerColumnMonths() );
dataProvider.push( getPickerColumnDays( 50 ) );
dataProvider.push( getPickerColumnYears( 80 ) );
picker = new Picker();
picker.itemHeight = 50;
picker.dataProvider = dataProvider;
picker.selectionChange( handlePickerSelection );
addChild( picker );
...
protected function handlePickerSelection( column:PickerColumn, index:int ):void
{
trace( "column: " + column + ", index: " + index );
}
Clone this wiki locally