Custom Right-click in Flash

Update: I’ve created a project on Google Code for this in the hopes of getting some Javascript experts to make the code work reliably in all the browsers that support the Actionscript External Interface.

By using a few lines of Javascript, and the External Interface I’ve been able to replace the default context-menu in Flash with a customized one. In my examples I use a simple color wheel in Flash and the color-picker component in Flex.

You can check out the pages here: Flash version, Flex version, Download code.

Here is the testing matrix so far:

  • Internet Explorer 7, Windows XP, passed
  • FireFox 2, Windows XP, passed

If you have a configuration that is different than any shown above then please comment and let me know the results. I’ll update the list as comments come in.

If it doesn’t work on your system it would be great if you took a crack at modifying the Javascript to support your browser. I’m pretty much out of the loop from here on out because I don’t have anything left to test on.

Below is the list of browser/OSes that the Flash External Interface works on. I would like to make sure that the Javascript works on all of the browser/OSes that are supporeted by the External Interface – listed below.

External Interface browser support
Browser Operating System
Internet Explorer 5.0 and later Windows
Netscape 8.0 and later Windows Macintosh
Mozilla 1.7.5 and later Windows Macintosh
Firefox 1.0 and later Windows Macintosh
Safari 1.3 and later Macintosh

The gist of how this works

It’s really pretty simple. We’ve all seen sites that have Flash content that have disabled the right-click altogether. I just took that idea and modified it by capturing the onMouseDown in Javascript and if it’s a right-click then notifying Flash via the External Interface. Flash then does its work which is very basic Actionscript.

Hopefully this will work on most browser/OSes and so encourage Adobe to just give us access from within Flash to fully customize the context-menu and not have to muck about in Javascript.

Sorry about disparaging Javascript. It isn’t Javascript’s fault that Internet Explorer is such a pain in the frakking ass. It took me 15 minutes to get this all to work in FireFox. It took 4 hours to get it to work in IE. (Insert Yosemite Sam cursing tirade here.)