System.setClipboard() inside event handler

丶灬走出姿态 提交于 2019-12-08 11:28:34

问题


Any thoughts on a good way to accomplish something along the lines of

var request:URLRequest = new URLRequest("http://myurl.com");
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, function(event:Event):void {
 System.setClipboard(loader.data);
});

in actionscript 3?

It seems as if System.setClipboard() isn't available inside an event handler (which makes at least some sense given what I know about Flash security).

Is there any way to:

  • get it to work?
  • or block on the URL load so that I can then call setClipboard() in the main event flow?

回答1:


The only solution is to show some alert (or other UI) to the user and wait for a click:

function completeHandler(event:Event):void
{
    Alert.show("Click OK to copy text to clipboard", "Alert",
        Alert.OK | Alert.CANCEL, this,
        callback, null, Alert.OK);
}

function callback(event:CloseEvent):void 
{
    // Check to see if the OK button was pressed.
    if (event.detail == Alert.OK)
        System.setClipboard(loader.data);
}



回答2:


For AIR use

Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT,"some Text value to clipboard");


来源:https://stackoverflow.com/questions/3427543/system-setclipboard-inside-event-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!