我在函數中使用Alert.show,我想從那裏獲取用戶答案。那麼我怎麼能做到這一點。問題是調用Alert.show將返回true或false值的函數取決於用戶的答案。 但它似乎在Alert.show中只允許傳入一個CloseHandler。這是一項新功能。並且因爲我可以從用戶回答的地方獲得用戶答案。我在一個函數中調用Alert.Show並希望從那裏得到結果(Flex,ActionScript)
真的感謝您的幫助 元
我在函數中使用Alert.show,我想從那裏獲取用戶答案。那麼我怎麼能做到這一點。問題是調用Alert.show將返回true或false值的函數取決於用戶的答案。 但它似乎在Alert.show中只允許傳入一個CloseHandler。這是一項新功能。並且因爲我可以從用戶回答的地方獲得用戶答案。我在一個函數中調用Alert.Show並希望從那裏得到結果(Flex,ActionScript)
真的感謝您的幫助 元
試試這個代碼
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate the Halo Alert control. -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CloseEvent;
// Event handler function uses a static method to show
// a pop-up window with the title, message, and requested buttons.
private function clickHandler(evt:Event):void {
Alert.show("Do you want to save your changes?", "Save Changes", Alert.YES|Alert.NO, this, alertClickHandler);
}
// Event handler function for displaying the selected Alert button.
private function alertClickHandler(evt:CloseEvent):void {
if (evt.detail == Alert.YES) {
status.text = "You answered Yes";
} else {
status.text = "You answered No";
}
}
// Event handler function changes the default Button labels and sets the
// Button widths. If you later use an Alert with the default Buttons,
// you must reset these values.
private function secondClickHandler(evt:Event):void {
Alert.buttonWidth = 100;
Alert.yesLabel = "Magenta";
Alert.noLabel = "Blue";
Alert.cancelLabel = "Green";
Alert.show("Select a color:", "Color Selection", Alert.YES|Alert.NO|Alert.CANCEL, this);
// Set the labels back to normal:
Alert.yesLabel = "Yes";
Alert.noLabel = "No";
}
]]>
</fx:Script>
<s:Panel title="Halo Alert Control Example"
width="75%"
horizontalCenter="0" verticalCenter="0">
<s:VGroup left="10" right="10" top="10" bottom="10">
<s:Label color="blue"
text="Click the button below to display a simple Alert window."/>
<s:Button label="Click Me" click="Alert.show('Hello World!', 'Message');"/>
<mx:HRule width="100%" />
<s:Label color="blue"
text="Click the button below to display an Alert window and capture the button pressed by the user."/>
<s:Button label="Click Me" click="clickHandler(event);"/>
<s:Label id="status" fontWeight="bold"/>
<mx:HRule width="100%" />
<s:Label color="blue"
text="Click the button below to display an Alert window that uses custom Button labels."/>
<s:Button label="Click Me" click="secondClickHandler(event);"/>
</s:VGroup>
</s:Panel>
</s:Application>
你可以做到這一點。 方法如下:
private function deleteItem_Confirmation_Handler(event:CloseEvent):void
{
if(event.detail == Alert.OK)
{
//Your code here
}
}
public function deleteValue():void
{
Alert.show("Are you sure you want to delete this item?", "confimation", Alert.OK | Alert.CANCEL, null, deleteItem_Confirmation_Handler, null, Alert.OK);
}
變化
evt.detail == Alert.YES
到
evt.detail == 1
Yes按鈕返回1 int值,無按鈕會返回一個int值爲2
謝謝,但在此代碼中,我無法獲得用戶答案以返回到調用deleteValue()的函數。 看起來Alert.show()無法從用戶的回答中調用http://flexed.wordpress.com/2006/08/04/alertshow-behavour-in-flex/ – 2010-11-16 06:06:18
@袁,你可以通過anonymus函數與Alert.show調用一樣,在事件監聽器中查看示例:http://www.kensodev.com/2009/07/14/add-a-parameter-or-even-more-then-one-to -flex-event-listener /這個顯示的事件監聽器,但Alert.show是相同的。請記住,這根本不是最佳實踐 – KensoDev 2010-11-16 08:44:20