Copy a text from Flash to to the sytem clipboard
I have found out that in order to copy a text from Flash to to the sytem clipboard we need a visible textarea, if we don't have it, we get an empty string. But in order to copy from clipboard to Flash we don't need a visible textarea (a hidden textarea is enough). This rule applies to the IE4 and above version, but I have written a IE 5 and above version which is much more simple and doesn't require any textareas.
Here is some background info for people interested in this subject.
In the Flash movie we have a dynamic text area with the variable name "text". We copy the clipboard content from and into it.
There is a button (copy) with that action:
on (release) {
var myText = _root.text;
getURL ("javascript:flashToClipBoard('"+myText+"'); void(0);");
}
When the button Copy is pressed the text in the dynamic textbox is passed as the argument of our javascript function.
I have posted the HTML code here:
//************************************IE4 and above version************************************//
Flash To Clipboard NOTE: If the text you have copied in Flash has carriage returns you cannot copy it back to the clipboard.
Here is some text that you can copy to the clipboard
(Choose Edit>Copy or right-click and copy).
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.
//************************************************************************//
If we don't use any form we can omit the id reference of the form in our scripts. The first form (id="pasteHere") is used to display the clipboard content, so you can do without it. flashToClipBoard function works fine when the textarea "hiddenBox" is not displayed.
function flashToClipBoard(flashInput) {
// the argument of this function is passed from Flash
hiddenBox.innerText = flashInput;
copiedText = hiddenBox.createTextRange();
copiedText.execCommand("Copy");
}
But the second function (flashToClipBoard) requires the textarea to be displayed (Style="display:none") will give us an empty string. (We cannot use a hidden textarea for that function)
But if we don't care for IE4.x browsers and we want to write a script for IE 5 and above browsers, things are much more easy for us. Here is the version for IE 5 and above:
(You can use the same Flash movie in that example)
//************************************IE5 and above version************************************//
Flash To Clipboard NOTE: If the text you have copied in Flash has carriage returns you cannot copy it back to the clipboard.
Here is some text that you can copy to the clipboard
(Choose Edit>Copy or right-click and copy).
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.
//************************************************************************
Netscape requires a trusted script to give access to the system clipboard. I have figured out the basic structure of such a script but (as I am not a Java programmer) I couldn't find out the exact syntax to instantiate the Java object and use its methods. Probably it should look like this
If someone knows the JAVA syntax and can post it on FORUMS, it would be nice.
It is also interesting that such a widely used browser as Internet Explorer 5.x has such a few security restrictions (regarding the clipboard access).
//actionscripts.org
转过来的