GhostWire Studios - Flash/Flex UI Components Development And Consulting Services
Quality User Interface Controls For Flash Application DevelopmentAspireUI Components

Nov 05 2009

[AS3] Hiding the Built-In Native MenuBar (And ContextMenu Items)

Published by sunny at 8:36 am under Flash,Flash AS3,Tips

By default, the SWFs you publish will show a native menu bar (the pull down menu showing the items File – View – Control – 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 – Create Projector… menu item from the native pull down menu.

flash menu bar


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.

To hide the native menu bar, set the showDefaultContextMenu property of the stage object to false:

stage.showDefaultContextMenu = false;

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

package 
{
	import flash.display.Sprite;
	import flash.events.Event;
 
	public class Module extends Sprite 
	{
		public function Module()
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
 
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
 
			// ** actual application code begins **
			// ** stage is no longer null **
			stage.showDefaultContextMenu = false;
		}
	}	
}


With that done, the SWF will no longer display the menu bar at the top when it is run locally:
without menu bar


Adobe’s documentation indicates that the showDefaultContextMenu property determines whether the default items in the Flash Player context menu should be shown or hidden. In actual fact, setting the property to false hides
(i) the built-in context menu items (except for the “Settings” and “About Adobe Flash Player” menu items);
AND
(ii) the native menu bar.

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.

Well, I guess it would be too cumbersome to call it “showDefaultContextMenuAndNativeMenuBar”…

pixelstats trackingpixel
Share or Bookmark This Post:
  • StumbleUpon
  • email
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Live
  • Yahoo! Buzz
  • Netvibes
  • NewsVine
  • Reddit
  • Slashdot
  • Technorati
  • BlinkList
  • Mixx
  • Diigo
  • Faves
  • Suggest to Techmeme via Twitter
  • Twitter

Other Posts You Might Enjoy:

       

No responses yet

Comments RSS

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word