<?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; keyDown</title>
	<atom:link href="http://blog.flexexamples.com/tag/keydown/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>Closing a pop up window using the keyboard in Flex</title>
		<link>http://blog.flexexamples.com/2008/08/04/closing-a-pop-up-window-using-the-keyboard-in-flex/</link>
		<comments>http://blog.flexexamples.com/2008/08/04/closing-a-pop-up-window-using-the-keyboard-in-flex/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 15:46:16 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[PopUpManager]]></category>
		<category><![CDATA[dispatchEvent()]]></category>
		<category><![CDATA[keyDown]]></category>
		<category><![CDATA[removePopUp()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/08/04/closing-a-pop-up-window-using-the-keyboard-in-flex/</guid>
		<description><![CDATA[<p>The following example shows how you can close a pop up window when a user presses the Escape key in Flex.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/PopUpManager_TitleWindow_keyDown_test/bin/srcview/source/main.mxml.html">View MXML</a></p> &#60;?xml version="1.0" encoding="utf-8"?&#62; &#60;!-- http://blog.flexexamples.com/2008/08/04/closing-a-pop-up-window-using-the-keyboard-in-flex/ --&#62; &#60;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white"&#62; &#60;mx:Script&#62; &#60;![CDATA[ import mx.managers.PopUpManager; private function button_click(evt:MouseEvent):void { var popUpTitleWindow:PopUpTitleWindow = new PopUpTitleWindow(); [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can close a pop up window when a user presses the Escape key in Flex.</p>
<p>Full code after the jump.</p>
<p><span id="more-731"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/PopUpManager_TitleWindow_keyDown_test/bin/srcview/source/main.mxml.html">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/08/04/closing-a-pop-up-window-using-the-keyboard-in-flex/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="top"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.managers.PopUpManager;

            private function button_click(evt:MouseEvent):void {
                var popUpTitleWindow:PopUpTitleWindow = new PopUpTitleWindow();
                PopUpManager.addPopUp(popUpTitleWindow, this, true);
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Button id="button"
            label="Launch Window"
            click="button_click(event);" /&gt;

&lt;/mx:Application&gt;
</pre>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/PopUpManager_TitleWindow_keyDown_test/bin/srcview/source/PopUpTitleWindow.mxml.html">PopUpTitleWindow.mxml</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/08/04/closing-a-pop-up-window-using-the-keyboard-in-flex/ --&gt;
&lt;mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
        showCloseButton="true"
        styleName="noPadding"
        layout="absolute"
        width="300"
        height="200"
        creationComplete="init();"
        resize="init();"
        close="titleWindow_close(event);"
        keyDown="titleWindow_keyDown(event);"&gt;

    &lt;mx:Style&gt;
        .noPadding {
            paddingBottom: 0;
            paddingTop: 0;
            paddingLeft: 0;
            paddingRight: 0;
        }
    &lt;/mx:Style&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.core.IFlexDisplayObject;
            import mx.events.CloseEvent;
            import mx.managers.PopUpManager;

            [Bindable]
            public var source:String;

            private function init():void {
                PopUpManager.centerPopUp(this);
                this.setFocus();
            }

            private function titleWindow_close(evt:CloseEvent):void {
                PopUpManager.removePopUp(evt.target as IFlexDisplayObject);
            }

            private function titleWindow_keyDown(evt:KeyboardEvent):void {
                if (evt.charCode == Keyboard.ESCAPE) {
                    this.dispatchEvent(new CloseEvent(CloseEvent.CLOSE));
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Label id="lbl"
            text="Press ESC to close this window."
            fontWeight="bold"
            truncateToFit="true"
            horizontalCenter="0"
            verticalCenter="0" /&gt;

    &lt;mx:ControlBar horizontalAlign="right" width="100%"&gt;
    &lt;/mx:ControlBar&gt;

&lt;/mx:TitleWindow&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/PopUpManager_TitleWindow_keyDown_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/PopUpManager_TitleWindow_keyDown_test/bin/main.html" width="100%" height="300"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Closing a pop up window using the keyboard in Flex on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/08/04/closing-a-pop-up-window-using-the-keyboard-in-flex/',contentID: 'post-731',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'dispatchEvent(),keyDown,removePopUp()',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/2008/08/04/closing-a-pop-up-window-using-the-keyboard-in-flex/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

