forked from: forked from: ContextMenu

by 9re forked from forked from: ContextMenu (diff: 7)
* Question

Does anyone know how to avoid SecurityError on Mac Safari?
♥0 | Line 58 | Modified 2010-10-29 10:59:06 | MIT License
play

ActionScript3 source code

/**
 * Copyright 9re ( http://wonderfl.net/user/9re )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/tg40
 */

// forked from 9re's forked from: ContextMenu
// forked from 9re's ContextMenu
package {
    import flash.events.Event;
    import flash.ui.ContextMenuClipboardItems;
    import flash.utils.setTimeout;
    import flash.events.MouseEvent;
    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;
            
            printLine("Select copy from the ContextMenu.");
            printLine("Does anyone kwow how to avoid SeccuriyError on Mac Safari?");
            
            graphics.beginFill(0xffffff);
            graphics.drawRect(0, 0, 465, 465);
            graphics.endFill();
            
             var _this:FlashTest = this;
            addEventListener(Event.COPY, function ():void {
                try {
                    printLine("trying to copy to clipboard...");
                    Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT, "copy test");
                } catch (e:Error) {
                    printLine("copying failed : " + e, errorFormat);
                    return;
                }
                printLine("copy succeeded!");
            });
            
            
            
            var str:String;
            contextMenu = new ContextMenu();
            contextMenu.hideBuiltInItems();
            contextMenu.clipboardMenu = true;
            contextMenu.clipboardItems.copy = true;
            
            function printLine(str:String, format:ElementFormat = null):void {
                format ||= normalFormat;
                factory.content = new TextElement(str, format);
                var line:TextLine = null;
                while (line = factory.createTextLine(line, 465)) {
                    line.y = yPos;
                    yPos += 16;
                    addChild(line);
                }
            }
            
        }
    }
}