In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

ContextMenu

You cannot copy to clipboard without user's mouse click or keyboard shortcut for OS copy(Ctrl + C / Cmd + C).
In the broswers other than Safari, you can copy to clipboard via clicking ContextMenu.
Safari does not let you do this and causes a SecurityError.

Anyway, try to click 'copy test' in the ContextMenu.

A Similar problem occurs when you change the display mode from the ContextMenu.
http://wonderfl.net/c/e3AO
Get Adobe Flash player
by 9re 27 Oct 2010
    Embed
/**
 * Copyright 9re ( http://wonderfl.net/user/9re )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7PRD
 */

package {
    import flash.text.engine.TextLine;
    import flash.text.engine.ElementFormat;
    import flash.text.engine.TextElement;
    import flash.text.engine.TextBlock;
    import flash.text.TextFormat;
    import flash.events.ContextMenuEvent;
    import flash.ui.ContextMenuItem;
    import flash.ui.ContextMenu;
    import flash.desktop.ClipboardFormats;
    import flash.desktop.Clipboard;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            var factory:TextBlock = new TextBlock;
            var errorFormat:ElementFormat = new ElementFormat;
            var normalFormat:ElementFormat;
            normalFormat = errorFormat.clone();
            errorFormat.color = 0xff0000;
            var yPos:int = 16;
            
            var _this:FlashTest = this;
            var item:ContextMenuItem = new ContextMenuItem('copy test', false);
            item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, function (e:ContextMenuEvent):void {
                try {
                    printLine("trying to copy to clipboard...");
                    stage.focus = _this;
                    Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, 'copy ok');
                } catch (e:SecurityError) {
                    printLine("copying failed : " + e, errorFormat);
                    return;
                }
                printLine("copy succeeded!");
            });
            
            function printLine(str:String, format:ElementFormat = null):void {
                format ||= normalFormat;
                factory.content = new TextElement(str, format);
                var line:TextLine = factory.createTextLine();
                line.y = yPos;
                yPos += 16;
                addChild(line);
            }
            
            contextMenu = new ContextMenu();
            contextMenu.hideBuiltInItems();
            contextMenu.customItems = [item];
        }
    }
}