System.setClipboard() inside event handler
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.se开发者_如何学JAVAtClipboard() 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?
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);
}
For AIR use
Clipboard.generalClipboard.setData(ClipboardFormats.TEXT_FORMAT,"some Text value to clipboard");
精彩评论