Flex 다중 선택 ComboBox
MyClassFactory 클래스는 다음과 같습니다.
import flash.display.DisplayObject;
import mx.core.ClassFactory;
import mx.states.OverrideBase;
public class MyClassFactory extends ClassFactory
{
public function MyClassFactory(generator:Class=null)
{
super(generator);
}
private var eventArray:Array=new Array();
private var _properties:Array=new Array();
public function addInitEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0,useWeakReference:Boolean=false):void{
eventArray.push({type:type,listener:listener,useCapture:useCapture,priority:priority,useWeakReference:useWeakReference});
}
public function addInitProperties(key:String,value:*):void{
_properties.push({key:key,value:value});
}
override public function newInstance():*{
trace("MyClassFactory.newInstance();");
var obj:*=super.newInstance();
var event:Object;
if(eventArray!=null&&eventArray.length>0&&obj as DisplayObject){
var i:int=0;
for(i=0;i<_properties.length;i++){
event=_properties[i];
if(event.value is Function){
obj[event.key]=event.value();
}else{
obj[event.key]=event.value;
}
}
for(i=0;i<eventArray.length;i++){
event=eventArray[i];
DisplayObject(obj).addEventListener(event.type,event.listener,event.useCapture,event.priority,event.useWeakReference);
}
}
return obj
}
}
MyComboBox 클래스는 다음과 같습니다.
import flash.events.Event;
import flash.events.MouseEvent;
import mx.collections.ArrayCollection;
import mx.controls.ComboBox;
import mx.controls.List;
import mx.controls.listClasses.ListBase;
import mx.core.ClassFactory;
import mx.events.FlexEvent;
import mx.events.FlexMouseEvent;
import mx.events.ListEvent;
import mx.events.SandboxMouseEvent;
public class MyComboBox extends ComboBox
{
public function MyComboBox()
{
super();
this.dropdownFactory=new MyClassFactory(List);
this.getDropdownFactory().addInitEventListener(ListEvent.CHANGE,dropdown_Change,false,1);
this.getDropdownFactory().addInitEventListener(MouseEvent.MOUSE_DOWN, dropdown_mouseDownHandler);
this.getDropdownFactory().addInitEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, dropdown_mouseOutsideHandler);
this.getDropdownFactory().addInitEventListener(FlexMouseEvent.MOUSE_WHEEL_OUTSIDE, dropdown_mouseOutsideHandler);
this.getDropdownFactory().addInitEventListener(SandboxMouseEvent.MOUSE_DOWN_SOMEWHERE, dropdown_mouseOutsideHandler);
this.getDropdownFactory().addInitEventListener(SandboxMouseEvent.MOUSE_WHEEL_SOMEWHERE, dropdown_mouseOutsideHandler);
this.getDropdownFactory().addInitProperties("allowMultipleSelection",true);
this.getDropdownFactory().addInitProperties("selectedItems",getSelectedItems);
}
private var _selectedItems:Array;
private var _selectedIndices:Array;
private var _separation:String=",";
[Bindable("change")]
[Bindable("valueCommit")]
public function get selectedItems():Array{
return _selectedItems==null?[]:_selectedItems;
}
public function set selectedItems(array:Array):void{
var t:String;
this._selectedItems=array;
this.text=selectedLabel;
}
[Bindable("change")]
[Bindable("valueCommit")]
public function get selectedIndices():Array{
return _selectedIndices!=null?_selectedIndices:[];
}
public function set selectedIndices(array:Array):void{
this._selectedIndices=array;
}
/**
* Label
* */
public function get separation():String{
return this._separation;
}
public function set separation(value:String):void{
this._separation=value;
}
public function getSelectedItems():Array{
return this.selectedItems;
}
/**
* ,Ctrl
* */
private var ctrlKey:Boolean=false;
private function dropdown_Change(event:ListEvent):void{
var listBase:ListBase=event.currentTarget as ListBase;
this.selectedItems=listBase.selectedItems;
this.selectedIndices=listBase.selectedIndices;
trace("dropdown_Change-----"+"selectedItems:"+selectedItems.length+"\t"+"selectedIndices:"+selectedIndices.length);
}
private function dropdown_mouseDownHandler(event:MouseEvent):void{
ctrlKey=event.ctrlKey;
}
private function dropdown_mouseDownOutSide(event:FlexMouseEvent):void{
close();
}
override public function close(trigger:Event=null):void{
if(!ctrlKey){
super.close(trigger);// Ctrl
}
}
override public function get selectedLabel():String
{
var array:Array=this.selectedItems;
var result:String="";
for(var i:int=0;i<array.length;i++){
result+=itemToLabel(array[i]);
if(i!=(array.length-1)){
result+=separation;
}
}
return result;
}
public function getDropdownFactory():MyClassFactory{
return super.dropdownFactory as MyClassFactory;
}
/**
* @private
*/
private function dropdown_mouseOutsideHandler(event:Event):void
{
trace("selectedItems:"+selectedItems.length+"\t"+"selectedIndices:"+selectedIndices.length);
if (event is MouseEvent)
{
var mouseEvent:MouseEvent = MouseEvent(event);
if (!hitTestPoint(mouseEvent.stageX, mouseEvent.stageY, true))
{
super.close(event);
}
}
else if (event is SandboxMouseEvent)
{
super.close(event);
}
}
}
호출 코드는 다음과 같습니다.
<my:MyComboBox width="180">
<my:dataProvider>
<s:ArrayCollection>
<fx:String> </fx:String>
<fx:String> </fx:String>
<fx:String> </fx:String>
<fx:String> </fx:String>
<fx:String> </fx:String>
</s:ArrayCollection>
</my:dataProvider>
</my:MyComboBox>
(Ctrl 키를 눌러 선택 항목을 여러 개 선택)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
콜백 함수를 Angular 하위 구성 요소에 전달이 예제는 구성 요소에 함수를 전달하는 것과 관련하여 최근에 직면한 문제를 다룰 것입니다. 국가 목록을 제공하는 콤보 상자 또는 테이블 구성 요소. 지금까지 모든 것이 구성 요소 자체에 캡슐화되었으며 백엔드에 대한 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.