我在函数中调用 Alert.Show 并希望从那里获取结果(Flex、ActionScript)

发布于 2024-10-02 21:34:34 字数 200 浏览 5 评论 0原文

我在函数中使用 Alert.show,我想从那里获得用户答案。那么我怎样才能实现这一目标。问题是调用 Alert.show 的函数将返回 true 或 false 值,具体取决于用户的答案。 但似乎在 Alert.show 中它只允许为此传入 CloseHandler 。这是一个新功能。从那以后,我可以从调用返回用户答案的​​地方获取用户答案。

真的很感谢您的帮助 元

I'm using the Alert.show in a function and I want to get the user answer from there. So how can I achieve this. The problem is the function that call Alert.show will return a true or false value depend the user answer.
but It seem that in Alert.show it only allow to pass in a CloseHandler for this. that is a new function. and since that I can get the user answer from where it is call to return the user answer.

Really thanks for help
Yuan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

肤浅与狂妄 2024-10-09 21:34:34

试试这个代码

<?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>

Try this code

<?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>
李白 2024-10-09 21:34:34

你可以这样做。
方法如下:

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);
    }

You can do this.
here's how:

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);
    }
萌︼了一个春 2024-10-09 21:34:34

更改

evt.detail == Alert.YES

evt.detail == 1

yes 按钮将返回 int 值 1,更改为 no 按钮将返回 int 值 2

change

evt.detail == Alert.YES

to

evt.detail == 1

the yes button returns an int value of 1, the no button would return an int value of 2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文