<?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>GhostWire Studios &#187; ContextMenu</title>
	<atom:link href="http://www.ghostwire.com/blog/archives/tag/contextmenu/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ghostwire.com/blog</link>
	<description>Flash UI Components</description>
	<lastBuildDate>Tue, 23 Aug 2011 03:51:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[AS3] Hiding the Built-In Native MenuBar (And ContextMenu Items)</title>
		<link>http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-native-menubar-and-contextmenu-items/</link>
		<comments>http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-native-menubar-and-contextmenu-items/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 08:36:41 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[ContextMenu]]></category>
		<category><![CDATA[Menu]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1287</guid>
		<description><![CDATA[By default, the SWFs you publish will show a native menu bar (the pull down menu showing the items File &#8211; View &#8211; Control &#8211; Help) when run locally. The same case applies to Projector (.exe) files published either from the Adobe Flash IDE, or created from local SWFs using the File &#8211; Create Projector&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>By default, the SWFs you publish will show a native menu bar (the pull down menu showing the items File &#8211; View &#8211; Control &#8211; Help) when run locally.  The same case applies to Projector (.exe) files published either from the Adobe Flash IDE, or created from local SWFs using the <em>File &#8211; Create Projector&#8230;</em> menu item from the native pull down menu.</p>
<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/menubar.png" alt="flash menu bar" title="flash menu bar" width="436" height="198" class="alignleft size-full wp-image-1288" /></p>
<p><!-- --><br />
In my opinion, this menu does not add any functionality to any Flash application, is as useless as the built-in contextMenu items, and should always be hidden.  Luckily, it takes only one line of code to hide the menu.</p>
<p><span id="more-1287"></span>To hide the native menu bar, set the <code>showDefaultContextMenu</code> property of the <code>stage</code> object to <code>false</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">showDefaultContextMenu</span> = <span style="color: #000000; font-weight: bold;">false</span>;</pre></div></div>

<p>You will need to ensure that the <code>stage</code> object is available, so the best place to do this is after your top-level container has been added to the display list:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package 
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Module <span style="color: #0066CC;">extends</span> Sprite 
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Module<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">else</span> addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>, init<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> 
		<span style="color: #66cc66;">&#123;</span>
			removeEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>, init<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// ** actual application code begins **</span>
			<span style="color: #808080; font-style: italic;">// ** stage is no longer null **</span>
			<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">showDefaultContextMenu</span> = <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>	
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><!-- --><br />
With that done, the SWF will no longer display the menu bar at the top when it is run locally:<br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/nomenubar.png" alt="without menu bar" title="without menu bar" width="436" height="198" class="alignleft size-full wp-image-1289" /></p>
<p><!-- --><br />
Adobe&#8217;s documentation indicates that the <code>showDefaultContextMenu</code> property determines whether the default items in the Flash Player context menu should be shown or hidden. In actual fact, setting the property to <code>false</code> hides<br />
 (i) the built-in context menu items (except for the &#8220;Settings&#8221; and &#8220;About Adobe Flash Player&#8221; menu items);<br />
<em>AND</em><br />
(ii) the native menu bar.</p>
<p>That makes the name of the property quite a misnomer, with no allusion to the fact that it can be used to hide the menu bar.</p>
<p>Well, I guess it would be too cumbersome to call it &#8220;showDefaultContextMenuAndNativeMenuBar&#8221;&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-native-menubar-and-contextmenu-items/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[AS3] Hiding the Built-In ContextMenu Items</title>
		<link>http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-contextmenu-items/</link>
		<comments>http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-contextmenu-items/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 07:15:23 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[ContextMenu]]></category>
		<category><![CDATA[FlashDevelop]]></category>
		<category><![CDATA[Menu]]></category>
		<category><![CDATA[User Experience]]></category>
		<category><![CDATA[UX]]></category>

		<guid isPermaLink="false">http://ghostwire.com/blog/?p=578</guid>
		<description><![CDATA[UPDATE: You may also refer to Hiding the Built-In Native MenuBar (And ContextMenu Items). In my opinion, the native right-click context menu is an odd legacy from the Flash Movies days. It may be useful when Flash is used as a video player, for animations and cartoons, in the absence of any proper custom UI. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE: You may also refer to <a href="http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-native-menubar-and-contextmenu-items/">Hiding the Built-In Native MenuBar (And ContextMenu Items)</a>.</strong></p>
<p>In my opinion, the native right-click context menu is an odd legacy from the Flash Movies days.  It may be useful when Flash is used as a video player, for animations and cartoons, in the absence of any proper custom UI.</p>
<p>If you are developing Flash applications, you should consider always hiding the native right-click Flash Player context menu&#8217;s built-in items.  Sure, you cannot get rid of the context menu completely, but you should at least hide the built-in items.  It makes the application look a lot more professional because the long list of built-in items are mostly irrelevant.</p>
<p><span id="more-578"></span>If you don&#8217;t do anything about it, when end-users right-click on your Flash application, the pop-up context menu will show &#8220;Zoom In&#8221;, &#8220;Zoom Out&#8221;, &#8220;Show All&#8221;, &#8220;Quality&#8221; (and sub menu), and &#8220;Print&#8230;&#8221; &#8211; all of these should be done in-application via properly designed user interface if the application allows these features to begin with.</p>
<p>For example, allowing end-users to zoom in/out without designing the application to handle these adjustments properly can be detrimental to the user experience. And if your application handles zooming in/out, it should have the proper UI to convey the feature to end-users rather than depending on the right-click menu.</p>
<p>Likewise, &#8220;Quality&#8221; adjustment is something that should be done in-application via a proper Options dialog where graphics, sounds, and perhaps other application-specific options are made available.</p>
<p>For multiple-frame SWFs (such as would be the case if you have a preloader frame), the built-in context menu items will also include, in addition to those mentioned above, &#8220;Play&#8221;, &#8220;Loop&#8221;, &#8220;Rewind&#8221;, &#8220;Forward&#8221; and &#8220;Back&#8221; &#8211; none of which should be of any relevance to RIAs. Letting the end-user activate any of these frame-manipulation actions can potentially mess up your application.</p>
<p><!-- --><br />
<strong>HTML</strong><br />
You can get rid of the built-in context menu items via the HTML container page, by defining the Flash object&#8217;s &#8220;menu&#8221; parameter as &#8220;false&#8221;.  If you are developing using the Adobe Flash IDE, you can generate the proper HTML page by unchecking the &#8220;Display Menu&#8221; option in the File -> Publish Settings dialog (HTML tab).  If you are developing using <a href="http://www.flashdevelop.org">FlashDevelop</a>, the &#8220;menu&#8221; parameter is already set to &#8220;false&#8221; by default.</p>
<p>However, using this method, you are depending on the HTML container page to tell the SWF to hide the context menu&#8217;s built-in items &#8211; if the SWF is run outside the HTML page, the menu items will no longer be hidden.  If you cannot guarantee that the SWF will be run within the HTML page you have generated, this method will not work well.  For example, if you are developing a Flash widget whereby only the SWF itself will be distributed, the menu items will not be hidden if the SWF is ultimately shown standalone, or within a HTML page where the &#8220;menu&#8221; parameter of the Flash object is not set to &#8220;false&#8221;.</p>
<p><!-- --><br />
<strong>ActionScript</strong><br />
You can hide the built-in items of the native context menu by inserting just two lines of code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">contextMenu</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">ContextMenu</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">contextMenu</span>.<span style="color: #0066CC;">hideBuiltInItems</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>You would typically insert the code into your top-level AS3 class as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package 
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">ui</span>.<span style="color: #0066CC;">ContextMenu</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite 
	<span style="color: #66cc66;">&#123;</span>		
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">contextMenu</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">ContextMenu</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">contextMenu</span>.<span style="color: #0066CC;">hideBuiltInItems</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>	
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Note: the &#8220;contextMenu&#8221; property is implemented by the <code>flash.displayObject.InteractiveObject</code> class.<br />
<em>Main -> Sprite -> DisplayObjectContainer -> InteractiveObject</em></p>
<p>In the above code, you are setting the &#8220;contextMenu&#8221; property of the top-level <code>Main</code> class instance to a new <code>ContextMenu</code> instance (where the built-in items are hidden).</p>
<p>Using this method, the instructions are internal to the SWF itself.  Whether the SWF is distributed and run standalone, or run within a HTML page, the built-in items will be hidden.  Also, regardless of the value of the &#8220;menu&#8221; parameter of the containing HTML page, the built-in items are going to be hidden (ie setting the &#8220;menu&#8221; parameter to &#8220;true&#8221; in the HTML page will not override this).</p>
<p>With the built-in menu items hidden, when the end-user right-clicks on your Flash application, the pop-up context menu will show only two items &#8211; &#8220;Settings&#8230;&#8221; and &#8220;About Adobe Flash Player&#8230;&#8221; &#8211; concise, sleek, a lot more professional looking.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/as3-hiding-the-built-in-contextmenu-items/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using uiMenu: Implementing &#8220;long press&#8221; contextual menu</title>
		<link>http://www.ghostwire.com/blog/archives/using-uimenu-implementing-long-press-contextual-menu/</link>
		<comments>http://www.ghostwire.com/blog/archives/using-uimenu-implementing-long-press-contextual-menu/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 12:16:49 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Aspire UI]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[ContextMenu]]></category>
		<category><![CDATA[Flash Components]]></category>
		<category><![CDATA[Menu]]></category>

		<guid isPermaLink="false">http://ghostwire.com/blog/?p=116</guid>
		<description><![CDATA[The “long press” context menu is an alternative to the typical right-click context menu. In this example, we will allow end-users to bring up a contextual menu by “long pressing” (pressing the left-mouse button down on a spot and holding it down for a predefined time).]]></description>
			<content:encoded><![CDATA[<p>The &#8220;long press&#8221; context menu is an alternative to the typical right-click context menu. In this example, we will allow end-users to bring up a contextual menu by &#8220;long pressing&#8221; (pressing the left-mouse button down on a spot and holding it down for a predefined time).</p>
<p>This example was implemented using <a href="/aspireui/docs/usage/uimenu">uiMenu</a> from the ActionScript 3.0 <a href="/aspireui/">Aspire UI</a> library.</p>
<p><span id="more-116"></span></p>
<p>Live demo:</p>
<ul>
<li>Pressing the mouse down anywhere on the dark area and holding it down, stationary, for half a second (500ms) will bring up a context menu.</li>
<li>If the CTRL KEY check box is selected, pressing the mouse down anywhere on the dark area while holding down the CTRL-KEY will bring up the context menu (without waiting for 500ms).</li>
<li>In this example, we have used 500ms for the delay &#8211; you can use another value in your own code, although 500ms is probably best for usability.</li>
</ul>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_ContextMenuDemo_760749972"
			class="flashmovie"
			width="300"
			height="300">
	<param name="movie" value="/aspireui/swf/ContextMenuDemo.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/aspireui/swf/ContextMenuDemo.swf"
			name="fm_ContextMenuDemo_760749972"
			width="300"
			height="300">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Here is the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">containers</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">controls</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #0066CC;">data</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">enums</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">managers</span>.<span style="color: #66cc66;">*</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #66cc66;">*</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">system</span>.<span style="color: #0066CC;">Capabilities</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Timer</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ContextMenuDemo <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// ** instances **</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> longPressTimer:Timer;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> popupMenu:uiMenu;		
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> menuModel:uiModel;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> ctrlKeyCheck:uiCheckBox;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> displayText:uiText;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> longPressDelay:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">500</span>; <span style="color: #808080; font-style: italic;">// ** delay of 500ms **</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ContextMenuDemo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>,init<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			uiSkins.<span style="color: #006600;">initialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;classic&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// ** using &quot;classic&quot; theme **</span>
			uiSkins.<span style="color: #006600;">manager</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">INIT</span>,main<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> main<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// ** main application code **</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// ** create a hotspot on the stage **</span>
			<span style="color: #000000; font-weight: bold;">var</span> hotspot:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			hotspot.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0.2</span><span style="color: #66cc66;">&#41;</span>;
			hotspot.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">200</span>,<span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span>;
			hotspot.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			hotspot.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">50</span>;
			hotspot.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">50</span>;
			addChild<span style="color: #66cc66;">&#40;</span>hotspot<span style="color: #66cc66;">&#41;</span>;
			hotspot.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>,on_startTimer,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			hotspot.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>,on_cancelTimer,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			hotspot.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>,on_cancelTimer,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// ** toggle CTRL key trigger **</span>
			ctrlKeyCheck = <span style="color: #000000; font-weight: bold;">new</span> uiCheckBox<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;CTRL KEY&quot;</span><span style="color: #66cc66;">&#41;</span>;
			ctrlKeyCheck.<span style="color: #006600;">move</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">250</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>ctrlKeyCheck<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// ** display text for reporting menu choice **</span>
			displayText = <span style="color: #000000; font-weight: bold;">new</span> uiText<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>displayText<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// ** popup menu XML **</span>
			<span style="color: #000000; font-weight: bold;">var</span> menuXML:<span style="color: #0066CC;">XML</span> =
			<span style="color: #66cc66;">&lt;</span>menu<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;View&quot;</span><span style="color: #66cc66;">&gt;</span>
				<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Large Icons&quot;</span>	group=<span style="color: #ff0000;">&quot;iconsize&quot;</span> <span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Medium Icons&quot;</span>	group=<span style="color: #ff0000;">&quot;iconsize&quot;</span> <span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Classic Icons&quot;</span>	group=<span style="color: #ff0000;">&quot;iconsize&quot;</span>  checked=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>item <span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Auto Arrange&quot;</span>	checked=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Align to Grid&quot;</span>	checked=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;/</span>item<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Sort By&quot;</span><span style="color: #66cc66;">&gt;</span>
				<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Name&quot;</span> <span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Size&quot;</span> <span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Type&quot;</span> <span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Date Modified&quot;</span> <span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;/</span>item<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>item <span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Refresh&quot;</span> <span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;</span>item <span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;</span>item label=<span style="color: #ff0000;">&quot;Help&quot;</span> <span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;/</span>menu<span style="color: #66cc66;">&gt;</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">// ** menu model using the XML **</span>
			menuModel = <span style="color: #000000; font-weight: bold;">new</span> uiModel<span style="color: #66cc66;">&#40;</span>menuXML<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> showPopup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			popupMenu = uiMenu.<span style="color: #006600;">popup</span><span style="color: #66cc66;">&#40;</span>menuModel,<span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>;
			popupMenu.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>uiMenuEvent.<span style="color: #006600;">MENU_SELECT</span>,on_menuSelect,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> on_cancelTimer<span style="color: #66cc66;">&#40;</span>evt:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>longPressTimer<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				displayText.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;long press cancelled&quot;</span>;
				<span style="color: #808080; font-style: italic;">// ** cancel long press timer **</span>
				longPressTimer.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>,on_timer<span style="color: #66cc66;">&#41;</span>;
				longPressTimer.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				longPressTimer = <span style="color: #000000; font-weight: bold;">null</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> on_startTimer<span style="color: #66cc66;">&#40;</span>evt:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>ctrlKeyCheck.<span style="color: #006600;">selected</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #66cc66;">&#40;</span>evt.<span style="color: #006600;">ctrlKey</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				showPopup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				displayText.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;pressing...&quot;</span>;
				<span style="color: #808080; font-style: italic;">// ** create a timer for detecting long press **</span>
				<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>longPressTimer == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					longPressTimer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span>longPressDelay<span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
				<span style="color: #b1b100;">else</span>
				<span style="color: #66cc66;">&#123;</span>
					longPressTimer.<span style="color: #006600;">reset</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
				<span style="color: #808080; font-style: italic;">// ** start long press timer **</span>
				longPressTimer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>,on_timer,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
				longPressTimer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> on_timer<span style="color: #66cc66;">&#40;</span>evt:TimerEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			displayText.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;popup menu shown&quot;</span>;
			longPressTimer.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>,on_timer<span style="color: #66cc66;">&#41;</span>;
			longPressTimer.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			longPressTimer = <span style="color: #000000; font-weight: bold;">null</span>;
			showPopup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> on_menuSelect<span style="color: #66cc66;">&#40;</span>evt:uiMenuEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			displayText.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Label: &quot;</span>+evt.<span style="color: #006600;">item</span>.<span style="color: #006600;">label</span>+<span style="color: #ff0000;">&quot; has been selected&quot;</span>;
			displayText.<span style="color: #0066CC;">text</span> += <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>group property value: &quot;</span>+evt.<span style="color: #006600;">item</span>.<span style="color: #006600;">group</span>;
			displayText.<span style="color: #0066CC;">text</span> += <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>checked property value: &quot;</span>+evt.<span style="color: #006600;">item</span>.<span style="color: #006600;">checked</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>Notes:</strong></p>
<ul>
<li>We start the timer when the mouse is pressed down on the hotspot, and cancel the timer if the mouse is moved or released.</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>50
51
52
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">			hotspot.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>,on_startTimer,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			hotspot.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>,on_cancelTimer,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
			hotspot.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">MOUSE_UP</span>,on_cancelTimer,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<ul>
<li>If the CTRL KEY check box is selected, we want to show the popup menu immediately when the mouse is pressed down so the timer is not used:
</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>108
109
110
111
112
113
114
115
116
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> on_startTimer<span style="color: #66cc66;">&#40;</span>evt:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>ctrlKeyCheck.<span style="color: #006600;">selected</span> <span style="color: #66cc66;">&amp;&amp;</span> <span style="color: #66cc66;">&#40;</span>evt.<span style="color: #006600;">ctrlKey</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				showPopup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				...</pre></td></tr></table></div>

<ul>
<li>The static uiMenu.popup() method takes two parameters:<br />
<code>uiMenu.popup(model,context);</code><br />
The &#8220;model&#8221; parameter is the uiModel object that will be used to populate the popup menu.<br />
The &#8220;context&#8221; parameter can be any DisplayObject on the stage. The popup menu will be positioned below this &#8220;context&#8221; (or above if necessary). If this parameter is set to the stage (as is the case in this example), the current mouse position when the method is called will be used when deciding where to place the popup menu.
</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>90
91
92
93
94
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> showPopup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			popupMenu = uiMenu.<span style="color: #006600;">popup</span><span style="color: #66cc66;">&#40;</span>menuModel,<span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>;
			popupMenu.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>uiMenuEvent.<span style="color: #006600;">MENU_SELECT</span>,on_menuSelect,<span style="color: #000000; font-weight: bold;">false</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<ul>
<li>The uiMenu.popup() method returns a reference to the uiMenu that is shown. The uiMenu dispatches the uiMenuEvent.MENU_SELECT event when the end-user selects a menu item.
</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>141
142
143
144
145
146
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> on_menuSelect<span style="color: #66cc66;">&#40;</span>evt:uiMenuEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			displayText.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Label: &quot;</span>+evt.<span style="color: #006600;">item</span>.<span style="color: #006600;">label</span>+<span style="color: #ff0000;">&quot; has been selected&quot;</span>;
			displayText.<span style="color: #0066CC;">text</span> += <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>group property value: &quot;</span>+evt.<span style="color: #006600;">item</span>.<span style="color: #006600;">group</span>;
			displayText.<span style="color: #0066CC;">text</span> += <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>checked property value: &quot;</span>+evt.<span style="color: #006600;">item</span>.<span style="color: #006600;">checked</span>;
		<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>See also: <a href="http://ghostwire.com/aspireui/docs/usage/uimenu">uiMenu usage notes</a></p>
<p><!-- --><br />
<strong>Aspire UI Components</strong><br />
Aspire UI is a library of Actionscript 3.0 (AS3) classes for building flexible and lightweight UI elements in Adobe Flash applications. Key features include easy skinning using PNG image files, automatic tab focus ordering, CSS text styles, and layout management. This is a pure AS3 library with no dependency on the Flex framework. You may experiment with the various features by downloading a trial version at<br />
<a href="http://ghostwire.com/aspireui/download/">http://ghostwire.com/aspireui/download/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/using-uimenu-implementing-long-press-contextual-menu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

