ContextMenu Problem

Have you ever tried to have “Delete”, “Cut”, “Paste” words inside flash context menu? It won’t work. I think flash player parse them as reserved key words. You may try “Delete.” it may work….. yet it not the solution you may look for. Well I have an examples to show codes that do not work, and that one that work…..

On the frame one you just copy and paste this segment of code. you will find no context menu with the name cut when you right click on the stage. You probably get the usual context menu.

Now try the same code by replacing “Cut.” it would work……

  1. // code showing problem
  2. var my_cm:ContextMenu = new ContextMenu();
  3. var menuItem_cmi:ContextMenuItem = new ContextMenuItem(”Cut”, emailHandler);
  4.  
  5. my_cm.customItems.push(menuItem_cmi);
  6. this.menu = my_cm;
  7.  
  8. function emailHandler() {
  9.       trace(”sending email”);
  10. }
  11.  

Not satisfied……Try out my last but tricky trick…

  1. //intermediate code
  2. var my_cm:ContextMenu = new ContextMenu();
  3. var menuItem_cmi:ContextMenuItem = new ContextMenuItem(”Cut.”, emailHandler);
  4.  
  5. my_cm.customItems.push(menuItem_cmi);
  6.  
  7. this.menu = my_cm;
  8.  
  9. function emailHandler() {
  10.        trace(”sending email”);
  11. }
  12.  

Modify the “Cut” to “Ctrl+Alt+255″ (ie type Cut then press ctrl and 2 5 5 in numeric keys) It will look similar to a space.But that’s the magic. Here is the code:

  1. // final code
  2. var my_cm:ContextMenu = new ContextMenu();
  3. var menuItem_cmi:ContextMenuItem = new ContextMenuItem(”Cut “, emailHandler);
  4.  
  5. my_cm.customItems.push(menuItem_cmi);
  6.  
  7. this.menu = my_cm;
  8.  
  9. function emailHandler() {
  10.        trace(”sending email”);
  11. }
  12.  

Now rock n roll ……happy times back again.

This entry was posted in AS2 Hacks. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>