Copy a text από Flash στο sytem clipboard

Λύσεις προβλημάτων για το δημοφιλές πρόγραμμα κατασκευής παρουσιάσεων στο διαδίκτυο.

Συντονιστές: WebDev Moderators, Super-Moderators

Απάντηση
Άβαταρ μέλους
Drizzt
Honorary Member
Δημοσιεύσεις: 993
Εγγραφή: 20 Μαρ 2002 01:00
Τοποθεσία: Kallithea
Επικοινωνία:

Copy a text από Flash στο sytem clipboard

Δημοσίευση από Drizzt » 20 Μάιος 2003 17:57

Μπορεί να γίνει κάτι τέτοιο, καθώς παίζει ο flash player με ένα Button να πέρνει την τιμή από text και να την πηγαίνει στο sytem clipboard :question:

Άβαταρ μέλους
tsiger
Honorary Member
Δημοσιεύσεις: 1431
Εγγραφή: 11 Νοέμ 2002 13:40
Τοποθεσία: Thessaloniki Observation Center
Επικοινωνία:

Copy a text από Flash στο sytem clipboard

Δημοσίευση από tsiger » 20 Μάιος 2003 18:47

Κώδικας: Επιλογή όλων

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************************************//
<html>
<head>
<title>Flash To Clipboard</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="Javascript">
<!--
// Flash to Clipboard
// By drZoode &#40;zoode@usa.net&#41;
// IE 4 and above specific execCommand methods
// are used to get access to the clipboard
// the innerText property of a hidden textarea &#40;id="hiddenBox"&#41;
// is used to manipulate the text range

function flashToClipBoard&#40;flashInput&#41; &#123;
        // the argument of this function is passed from Flash
        myForm.hiddenBox.innerText = flashInput;
        copiedText = myForm.hiddenBox.createTextRange&#40;&#41;;
        copiedText.execCommand&#40;"Copy"&#41;;
        pastedText = myForm.pasteHere.createTextRange&#40;&#41;;
        pastedText.execCommand&#40;"Paste"&#41;;
&#125;

function clipBoardToFlash&#40;&#41; &#123;
        pastedText = myForm.pasteHere.createTextRange&#40;&#41;;
        pastedText.execCommand&#40;"Paste"&#41;;
        var goToFlash = myForm.pasteHere.innerText;
        // we use a Flash Method to *simulate* the pasting effect
        // as this is a IE only exercise we do not care for Netscape friendly syntax
        window.movie.SetVariable&#40;"_root.text", goToFlash&#41;;
&#125;
//-->
</script>
</head>

<body bgcolor="#999999" text="#000000">

<form id="myForm">
<table width="600" border="0" cellspacing="5" cellpadding="5">
<tr>
<td>
<textarea rows="10" cols="50" id="hiddenBox" style="display&#58;none" name="textarea">
</textarea>
</td>
</tr>
<tr>
<td>
<p>The text in the clipboard will appear here.
<br>You can open a text editor program &#40;e.g. Notepad&#41; and paste the text there.</p>
</td>
</tr>
<tr>
<td>
<textarea rows="6" cols="40" id="pasteHere" name="textarea2">
</textarea>
</td>
</tr>
</table>
<br>
<br>
</form>

<OBJECT classid="clsid&#58;D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http&#58;//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
WIDTH=500 HEIGHT=350 ID="movie">
<PARAM NAME=movie VALUE="clipboard.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#999999> <EMBED src="clipboard.swf" quality=high bgcolor=#999999 WIDTH=500 HEIGHT=350 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http&#58;//www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>
</OBJECT>
<p> NOTE&#58; If the text you have copied in Flash has carriage returns you cannot copy it back to the clipboard.
<p><b>Here is some text that you can copy to the clipboard</b>
<br>&#40;Choose Edit>Copy or right-click and copy&#41;.
<br>
<br>'Twas brillig, and the slithy toves
<br>Did gyre and gimble in the wabe&#58;
<br>All mimsy were the borogoves,
<br>And the mome raths outgrabe.
<br><br>
<button onClick = "clipBoardToFlash&#40;&#41;">Paste to Flash </button>
</p>
</body>
</html>
//************************************************************************//

If we don't use any form we can omit the id reference of the form in our scripts. The first form &#40;id="pasteHere"&#41; 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&#40;flashInput&#41; &#123;
        // the argument of this function is passed from Flash
        hiddenBox.innerText = flashInput;
        copiedText = hiddenBox.createTextRange&#40;&#41;;
        copiedText.execCommand&#40;"Copy"&#41;;
&#125;

But the second function &#40;flashToClipBoard&#41; requires the textarea to be displayed &#40;Style="display&#58;none"&#41; will give us an empty string. &#40;We cannot use a hidden textarea for that function&#41;

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&#58;
&#40;You can use the same Flash movie in that example&#41;
//************************************IE5 and above version************************************//
<html>
<head>
<title>Flash To Clipboard</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="Javascript">
<!--
// Flash to Clipboard - IE 5 and above version
// By drZoode &#40;zoode@usa.net&#41;
// this version uses IE 5 and above specific clipboardData object

function flashToClipBoard&#40;flashInput&#41; &#123;
        // the argument of this function is passed from Flash
        var fromFlash = window.clipboardData.setData&#40;'Text', flashInput&#41;;
&#125;
function clipBoardToFlash&#40;&#41; &#123;
        var goToFlash = window.clipboardData.getData&#40;'Text'&#41;;
        // we use a Flash Method to *simulate* the pasting effect
        // as this is a IE only exercise we do not care for Netscape friendly syntax
        window.movie.SetVariable&#40;"_root.text", goToFlash&#41;;
&#125;
//-->
</script>
</head>

<body bgcolor="#999999" text="#000000">
<OBJECT classid="clsid&#58;D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http&#58;//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
WIDTH=500 HEIGHT=350 ID="movie">
<PARAM NAME=movie VALUE="clipboard.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#999999> <EMBED src="clipboard.swf" quality=high bgcolor=#999999 WIDTH=500 HEIGHT=350 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http&#58;//www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>
</OBJECT>
<p> NOTE&#58; If the text you have copied in Flash has carriage returns you cannot copy it back to the clipboard.
<p><b>Here is some text that you can copy to the clipboard</b>
<br>&#40;Choose Edit>Copy or right-click and copy&#41;.
<br>
<br>'Twas brillig, and the slithy toves
<br>Did gyre and gimble in the wabe&#58;
<br>All mimsy were the borogoves,
<br>And the mome raths outgrabe.
<br><br>
<button onClick = "clipBoardToFlash&#40;&#41;">Paste to Flash </button>
</p>
</body>
</html>
//************************************************************************

Netscape requires a trusted script to give access to the system clipboard. I have figured out the basic structure of such a script but &#40;as I am not a Java programmer&#41; I couldn't find out the exact syntax to instantiate the Java object and use its methods. Probably it should look like this

<SCRIPT LANGUAGE="JavaScript" ARCHIVE="myArchive.jar" ID="myID">
function getMyClipboard&#40;&#41; &#123;
        netscape.security.PrivilegeManager.enablePrivilege&#40;"UniversalSystemClipboardAccess"&#41;;
        // **************
        // instantiate the Java object and use its methods
        // cb = new Packages.java.awt.datatransfer.Clipboard&#40;String&#41;;
        // myCb = cb.getContents&#40;Object&#41;;
        //document.write&#40;'My clipboard&#58;<BR>'+myCb&#41;;
        // **************
&#125;
</SCRIPT>

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 &#40;regarding the clipboard access&#41;.

Πηγή: ActionsScript.org

Άβαταρ μέλους
Drizzt
Honorary Member
Δημοσιεύσεις: 993
Εγγραφή: 20 Μαρ 2002 01:00
Τοποθεσία: Kallithea
Επικοινωνία:

Copy a text από Flash στο sytem clipboard

Δημοσίευση από Drizzt » 21 Μάιος 2003 10:29

Σωστά όλα αυτά, αλλά δεν μπορείς να τρέξεις java script κάτω από director αλλά μόνο στον browser...

Yπάρχει άλλος τρόπος... χωρίς java script :question:

Άβαταρ μέλους
tsiger
Honorary Member
Δημοσιεύσεις: 1431
Εγγραφή: 11 Νοέμ 2002 13:40
Τοποθεσία: Thessaloniki Observation Center
Επικοινωνία:

Copy a text από Flash στο sytem clipboard

Δημοσίευση από tsiger » 21 Μάιος 2003 14:03

se ti douleveis flash i se director?

Άβαταρ μέλους
Drizzt
Honorary Member
Δημοσιεύσεις: 993
Εγγραφή: 20 Μαρ 2002 01:00
Τοποθεσία: Kallithea
Επικοινωνία:

Copy a text από Flash στο sytem clipboard

Δημοσίευση από Drizzt » 21 Μάιος 2003 14:43

Σε director
Κάποια πεδία μέσα στο director θα είναι με flash.

Απάντηση

Επιστροφή στο “Flash γενικά”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες