<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Examples &#187; CloseEvent.CLOSE</title>
	<atom:link href="http://blog.flexexamples.com/tag/closeevent-close/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Detecting which button a user pressed to dismiss an Alert dialog</title>
		<link>http://blog.flexexamples.com/2007/07/18/detecting-which-button-a-user-pressed-to-dismiss-an-alert-dialog/</link>
		<comments>http://blog.flexexamples.com/2007/07/18/detecting-which-button-a-user-pressed-to-dismiss-an-alert-dialog/#comments</comments>
		<pubDate>Thu, 19 Jul 2007 05:55:11 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[Alert]]></category>
		<category><![CDATA[CloseEvent]]></category>
		<category><![CDATA[CloseEvent.CLOSE]]></category>
		<category><![CDATA[detail]]></category>
		<category><![CDATA[show()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/07/18/detecting-which-button-a-user-pressed-to-dismiss-an-alert-dialog/</guid>
		<description><![CDATA[<p>In the previous post we looked at creating and displaying a basic, bare[ly usable], Alert dialog. Now we&#8217;ll look at how to determine which button a user pressed to dismiss the dialog.</p> <p></p> <p>Again, the example isn&#8217;t overly complex, or amazing, but it shows how you can build some basic logic into an application where you [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous post we looked at creating and displaying a basic, bare[ly usable], Alert dialog. Now we&#8217;ll look at how to determine which button a user pressed to dismiss the dialog.</p>
<p><span id="more-9"></span></p>
<p>Again, the example isn&#8217;t overly complex, or amazing, but it shows how you can build some basic logic into an application where you can commit or reject an action based on a user&#8217;s feedback.</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Alert_close_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/07/18/detecting-which-button-a-user-pressed-to-dismiss-an-alert-dialog/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.Alert;
            import mx.events.CloseEvent;

            private var alert:Alert;

            private function showAlert():void {
                var text:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.nntHello World";
                var title:String = "This is the title of the Alert window";

                alert = Alert.show(text, title, Alert.YES | Alert.NO);
                alert.addEventListener(CloseEvent.CLOSE, alert_close);

                message.text = "";
            }

            private function alert_close(evt:CloseEvent):void {
                switch (evt.detail) {
                    case Alert.CANCEL:
                        message.text = "You pressed `" + Alert.cancelLabel + "`.";
                        break;
                    case Alert.NO:
                        message.text = "You pressed `" + Alert.noLabel + "`.";
                        break;
                    case Alert.OK:
                        message.text = "You pressed `" + Alert.okLabel + "`.";
                        break;
                    case Alert.YES:
                        message.text = "You pressed `" + Alert.yesLabel + "`.";
                        break;
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Button label="Alert.show()" click="showAlert();" /&gt;
    &lt;mx:Label id="message" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Alert_close_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Alert_close_test/bin/main.html" width="100%" height="200"></iframe></p>
<p class="new">Instead of manually adding an event listener for the <code>close</code> event, you could also specify the <code>closeHandler</code> argument in the <code>Alert.show()</code> method, as seen in the following example:</p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/Alert_closeHandler_test/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2007/07/18/detecting-which-button-a-user-pressed-to-dismiss-an-alert-dialog/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.controls.Alert;
            import mx.events.CloseEvent;

            private var alert:Alert;

            private function showAlert():void {
                var text:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.nntHello World";
                var title:String = "This is the title of the Alert window";

                alert = Alert.show(text, title, Alert.YES | Alert.NO, null, alert_close);

                message.text = "";
            }

            private function alert_close(evt:CloseEvent):void {
                switch (evt.detail) {
                    case Alert.CANCEL:
                        message.text = "You pressed `" + Alert.cancelLabel + "`.";
                        break;
                    case Alert.NO:
                        message.text = "You pressed `" + Alert.noLabel + "`.";
                        break;
                    case Alert.OK:
                        message.text = "You pressed `" + Alert.okLabel + "`.";
                        break;
                    case Alert.YES:
                        message.text = "You pressed `" + Alert.yesLabel + "`.";
                        break;
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Button label="Alert.show()" click="showAlert();" /&gt;
    &lt;mx:Label id="message" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/Alert_closeHandler_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/Alert_closeHandler_test/bin/main.html" width="100%" height="200"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Detecting which button a user pressed to dismiss an Alert dialog on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/07/18/detecting-which-button-a-user-pressed-to-dismiss-an-alert-dialog/',contentID: 'post-9',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'CloseEvent.CLOSE,detail,show()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/07/18/detecting-which-button-a-user-pressed-to-dismiss-an-alert-dialog/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

