views:

43

answers:

1

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  A: 

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);
}
Maxim Kachurovskiy