2011-12-15 3 views
0

맞춤 구성 요소를 만들지 않고 combobox 하위 (텍스트 입력 및 버튼)에 액세스해야합니다. 가장 좋은 방법은 맞춤 구성 요소를 만드는 것이지만 여전히 textinput과 같은 콤보 상자에 액세스하여 해당 이벤트를 수신해야한다는 것입니다. 어떤 도움이 필요합니까?Flex 콤보 박스 하위 (textInput, button) 액세스

답변

0

이처럼 콤보 상자 TextInput의 이벤트를 추가 할 수 있습니다

myComboBox.textInput.addEventListener(TextOperationEvent.CHANGE, myFunction); 

을 TextInput 구성 개체가 콤보 상자 개체 (myComboBox.textInput)의 자식이기 때문이다.


여기에 전체 작업 예를

<?xml version="1.0" encoding="utf-8"?> 
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="creationCompleteHandler(event)"> 

    <fx:Script> 
     <![CDATA[ 
      import mx.collections.ArrayCollection; 
      import mx.events.FlexEvent; 

      import spark.events.IndexChangeEvent; 
      import spark.events.TextOperationEvent; 

      [Bindable] 
      private var _dp:ArrayCollection = new ArrayCollection([ 
       {id : "1", name : "Paul"}, 
       {id : "2", name : "Andrew"}, 
       {id : "2", name : "Bob"} 
      ]); 

      protected function creationCompleteHandler(event:FlexEvent):void 
      { 
       myComboBox.textInput.addEventListener(TextOperationEvent.CHANGE, showTextInputValue); 
       myComboBox.addEventListener(IndexChangeEvent.CHANGE, showComboValue); 
      } 

      protected function showTextInputValue(event:TextOperationEvent):void 
      { 
       textFieldValue.text = "myComboBox.textInput : " + event.currentTarget.text; 
      } 

      protected function showComboValue(event:IndexChangeEvent):void 
      { 
       if (event.newIndex > -1) 
        comboBoxValue.text = "myComboBox selected item is : " + myComboBox.selectedItem.name; 
      } 

     ]]> 
    </fx:Script> 

    <s:layout> 
     <s:VerticalLayout/> 
    </s:layout> 

    <s:ComboBox id="myComboBox" labelField="name" dataProvider="{_dp}"/> 

    <mx:Spacer height="100"/> 

    <s:Label id="textFieldValue"/> 

    <s:Label id="comboBoxValue"/> 

</s:WindowedApplication> 
입니다
0

당신은 콤보 상자에 Event.ADDED에 대한 이벤트 리스너를 추가하고 event.target 확인할 수 있습니다 '지점을 핀의 유형을 원하는 표시 객체 (예 : if (event.target is TextField) doStuff();) 당신은 콤보 상자에 액세스 할 수 없습니다'속성을 (텍스트 필드를 대체하는 또는 다른 버튼이있는 버튼)을 추가 할 수 있지만 스테이지에 추가 된 인스턴스는 수정할 수 있습니다.