2013-05-11 49 views
2

我需要在用戶在下拉列表中選擇某個選項後顯示警告對話框。如果彈出下拉列表,它會打開警報對話框

這是一個簡單的flex下拉列表(flash builder 4.6),打開一個警告對話框。當我這樣做時,下拉列表會「卡住」下來,這意味着在選擇選項後,通常下拉列表會關閉,但當我顯示警報時,它將保持打開狀態,並且必須再次單擊選擇關閉它。

下拉列表MXML:

 <s:DropDownList id="typeEventDropDownList" 
         change="typeEventDropDownList_changeHandler(event)" 
         selectedIndex="0"> 
      <s:layout> 
       <s:VerticalLayout requestedRowCount="10"/> 
      </s:layout> 
      <s:dataProvider> 
       <s:ArrayList source="[ChooseAction,a,b,c,d,e,f,g,h,i]" /> 
      </s:dataProvider> 
     </s:DropDownList> 

下拉列表處理程序:

protected function typeEventDropDownList_changeHandler(event:IndexChangeEvent):void 
      { 
        // if this alert is called, the drop down list 'sticks' open. if the alert is removed, it closes normally 
      Alert.show("bla bla bla", "Warning",mx.controls.Alert.OK , this, null); // does not matter if a method is called from here 
         } 

我之前已經和警報後嘗試使用closeDropDown(甚至調用OpenDropDown)的幾個組合對話框,這似乎沒有什麼區別:

  typeEventDropDownList.openDropDown(); //have tried opening and closing, closing only, before and after alert - no difference 
     typeEventDropDownList.closeDropDown(true); // have tried true and false no difference 
+0

Alert盒子控件中的'this'是否引用DropDownList?或者DropDownList的一些父項? – JeffryHouser 2013-05-11 16:41:57

+2

我認爲如果您聽取'close'事件而不是'change'事件,則會在警報顯示之前關閉下拉菜單。當然,如果你確實需要知道'selectedIndex'是否真的發生了變化,你可能必須自己確定。 – RIAstar 2013-05-11 17:03:20

+0

下拉菜單出現在TitleWindow內的組中。所以我相信'這是'TitleWindow。 – 2013-05-11 17:10:56

回答

0

你在哪裏把關閉清單代碼?這應該工作:

protected function typeEventDropDownList_changeHandler(event:IndexChangeEvent):void 
{ 
    typeEventDropDownList.closeDropDown(true); 
    Alert.show("bla bla bla", "Warning",mx.controls.Alert.OK , this, null); 
} 
1

您可以像

protected function typeEventDropDownList_changeHandler(event:IndexChangeEvent):void 
{ 
callLater(DisplayAlert); 
} 

protected function DisplayAlert() 
{ 
//Display your alert here , i.e., Alert.show() 
} 

它爲我工作。