PDA

Просмотр полной версии : Combobox переписал. не найду ошибки арея


locust19
21.05.2010, 15:49
Переписал функции combobox для мультивыбора, должно всегда выдавать ареем.. если больше 1 элемента выберешь будет мне арей. если 1 то ни стринг ни бог его знает что.. не могу достать и сообразить, помогите пожалуйста, как исправить?

определенно решение лежит тут

причем очень интересно выходит.. когда данные с dataprovider приходят. то первое поле попадает в арей [0], но увы при выборе одного элемента из бокса ничего не возвращает_ и также выбирает, но стоит для этого нажать сперва ctr и отпустить его с одним выбранным элементом

override protected function keyDownHandler( event:KeyboardEvent ):void
{
super.keyDownHandler( event );

this.ctrlKeyPressed = event.ctrlKey;

if( this.ctrlKeyPressed == true )
{
dropdown.allowMultipleSelection = true;
}
}

/**
* This function prevents the ComboBox from closing if CtrlKey is pressed
* Else it fires a Change event to update selectedItems array on close
*
* If CtrlKey is not pressed then,
* ComboBox dropdown is closed and change event is dispatched.
*
* 'dropdown' in a ComboBox is a List component
**/
override protected function keyUpHandler( event:KeyboardEvent ):void
{
super.keyUpHandler( event );
this.ctrlKeyPressed = event.ctrlKey;

if ( this.ctrlKeyPressed == false )
{
this.close();
var changeEvent:ListEvent = new ListEvent( ListEvent.CHANGE );
this.dispatchEvent( changeEvent );
this.selectedIndex = -1;
}
}

...
/**
* 'selectedItems' Setter
**/
public function set selectedItems( value:Array ):void
{
if( this.dropdown )
{
this.dropdown.selectedItems = value;
}
}


/**
* 'selectedItems' Getter
**/
[Bindable("change")]
public function get selectedItems( ) : Array

{
if ( this.dropdown )
return this.dropdown.selectedItems
else
return null;
}


/**
* 'selectedIndices' Setter
**/
public function set selectedIndices( value:Array ) : void
{
if ( this.dropdown )
{
this.dropdown.selectedIndices = value;
}
}


/**
* 'selectedIndices' Getter
**/
[Bindable("change")]
public function get selectedIndices( ) : Array
{
if ( this.dropdown )
return this.dropdown.selectedIndices;
else
return null;
}
}


далее следует полный код

package
{
import flash.events.Event;
import flash.events.KeyboardEvent;

import mx.controls.ComboBox;
import mx.events.ListEvent;

public class MultiSelectComboBox extends ComboBox
{

private var ctrlKeyPressed:Boolean = false; //Control Key Pressed

/**
* This function checks whether the CtrlKey is pressed.
* If CtrlKey is pressed then,
* multiple selection is enabled for the ComboBox dropdown.
**/
override protected function keyDownHandler( event:KeyboardEvent ):void
{
super.keyDownHandler( event );

this.ctrlKeyPressed = event.ctrlKey;

if( this.ctrlKeyPressed == true )
{
dropdown.allowMultipleSelection = true;
}
}

/**
* This function prevents the ComboBox from closing if CtrlKey is pressed
* Else it fires a Change event to update selectedItems array on close
*
* If CtrlKey is not pressed then,
* ComboBox dropdown is closed and change event is dispatched.
*
* 'dropdown' in a ComboBox is a List component
**/
override protected function keyUpHandler( event:KeyboardEvent ):void
{
super.keyUpHandler( event );
this.ctrlKeyPressed = event.ctrlKey;

if ( this.ctrlKeyPressed == false )
{
this.close();
var changeEvent:ListEvent = new ListEvent( ListEvent.CHANGE );
this.dispatchEvent( changeEvent );
this.selectedIndex = -1;
}
}

/**
* This function prevents the ComboBox from closing if CtrlKey is pressed on a Close Event
**/
override public function close( trigger:Event=null ):void
{
if( this.ctrlKeyPressed == false )
{
super.close( trigger );
this.selectedIndex = -1;
}
}


/**
* 'selectedItems' Setter
**/
public function set selectedItems( value:Array ):void
{
if( this.dropdown )
{
this.dropdown.selectedItems = value;
}
}


/**
* 'selectedItems' Getter
**/
[Bindable("change")]
public function get selectedItems( ) : Array

{
if ( this.dropdown )
return this.dropdown.selectedItems
else
return null;
}


/**
* 'selectedIndices' Setter
**/
public function set selectedIndices( value:Array ) : void
{
if ( this.dropdown )
{
this.dropdown.selectedIndices = value;
}
}


/**
* 'selectedIndices' Getter
**/
[Bindable("change")]
public function get selectedIndices( ) : Array
{
if ( this.dropdown )
return this.dropdown.selectedIndices;
else
return null;
}

/**
* 'MultiSelectComboBox' constructor
**/
public function MultiSelectComboBox()
{
super();
}

}
}

разобрался с -1 на 1 нужно было заменить