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 느릅나무™