Flex Array의 Filter Method 사용하기

Flex/Flex 2.* 2009. 6. 1. 16:55
□ Array Class - public Method
filter(callback:Function, thisObject:* = null) : Array
배열내의 각 아이템에 대해 테스트 함수를 실행해, 지정된 함수에 대해 true를 돌려주는 모든 아이템을 포함한 새로운
배열을 작성합니다.

○ 원하는 Box만 Array 형태로 수집하고 싶은 경우
<mx:VBox id="vbox">
   <mx:Vbox id="b1" name="BOX"/>
   <mx:Vbox id="b2" name="BOX"/>
   <mx:Vbox id="b3" name="HBOX"/>
   <mx:Vbox id="b4" name="BOX"/>
</mx:VBox>
private function text() : void {
   var arr : Array = vbox.getChildren().filter(isBox);   // getChildren()는 Box의 자식을 Array로 반환
}

private function isBox(item : *, index : int, arr : Array) : Boolean {
   if(item.name == "BOX") {
      return true;
   } else {
      return false;
   }
   return false;
}
posted by 느릅나무™
//로우 색처리 ===========================================================
private var _rowColorFunction : Function;

public function set rowColorFunction( f : Function ) : void {
   this._rowColorFunction = f;
}
public function get rowColorFunction() : Function {
   return this._rowColorFunction;
}

private var displayWidth : Number;

override protected function updateDisplayList( unscaledWidth : Number, unscaledHeight : Number) : void {
   super.updateDisplayList(unscaledWidth, unscaledHeight);
   if (displayWidth != unscaledWidth - viewMetrics.right - viewMetrics.left) {
      displayWidth = unscaledWidth - viewMetrics.right - viewMetrics.left;
   }
}

override protected function drawRowBackground(s : Sprite, rowIndex : int, y : Number, height : Number, color : uint, dataIndex : int) : void {
   if( this.rowColorFunction != null ) {
      if( dataIndex < (this.dataProvider as ArrayCollection).length ) {
         var item:Object = (this.dataProvider as ArrayCollection).getItemAt(dataIndex);
         color = this.rowColorFunction.call(this, item, color);
      }
   }
   super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
}
사용방법
private function selectTypeColor( item : Object, color : uint) : uint {
   if( item['컬렉션명'] == "값" )  {
      return 0xFFFF00;
   }
   return color;
}


   
      
         
         
      
   

posted by 느릅나무™

Flex 각 랜더러 자체의 팁

Flex/Flex 2.* 2009. 2. 22. 22:34
private function onItemRollOver ( event : ListEvent ) : void {
   var rowIndex :int = event.rowIndex-1;
   var colIndex :int = event.columnIndex;
   var arrCol :ArrayCollection = ArrayCollection ( dg.dataProvider );
   var item :Object = arrCol.getItemAt ( rowIndex );
   var key :String = DataGridColumn ( dg.columns [ colIndex ] ).dataField;
   var tipKey :String = key + "CODE";
   DataGridColumn ( dg.columns [ colIndex ] ).showDataTips = true;
   DataGridColumn ( dg.columns [ colIndex ] ).dataTipField = tipKey;
} 
데이터그리드의 itemRollOver에서 위 메소드를 호출하도록 하면... 각 렌더러 자체의 팁이 나온다
dataTipField 에 필드명을 지정 했는데 해당 필드명이 없을 경우 알아서 자동으로 자신의 필드명으로 세팅,  
추가적으로 dataTipFunction도 컬럼에 달수 있음.
posted by 느릅나무™