PDA

View Full Version : Copying selected Dynamic Text using a button???


dprichard
12-02-2005, 01:46 PM
Heres my problem! I'm trying to create a desktop simulation for a client that consist of a screenshot of "WordPad" and some text within it. They want to have the user select the word (Jack) from the first sentence and use the copy and paste buttons under the edit menu to paste it to the second sentence.

Is there a way to set the copy button to target the highlighted text in the text field and somehow copy it to the clipboard? I've racked my brain for days and can't come up with a solution. Thanks for any help! :confused: :confused: :confused:

hasseltje
12-03-2005, 08:12 AM
Can't think of a way to do this with a button, but ain't it good enough just to teach people to use their rightmousebutton --> copy and paste on the second line??

dijiyd
12-03-2005, 08:46 AM
You might work it out with the following (untested):

System.setClipboard( mytextfield.text.slice( Selection.getBeginIndex(), Selection.getEndIndex() ) );


er... too messy? Basically:
system.setClipboard sets the cliboard
mytextfield.text is a string
string has a method slice, which returns a substring
Selection.getBegin and EndIndex() returns the respective positions of the selected text.
Hope it works out.

Suicidal.Banana
12-03-2005, 09:29 AM
You might work it out with the following (untested):

System.setClipboard( mytextfield.text.slice( Selection.getBeginIndex(), Selection.getEndIndex() ) );


er... too messy? Basically:
system.setClipboard sets the cliboard
mytextfield.text is a string
string has a method slice, which returns a substring
Selection.getBegin and EndIndex() returns the respective positions of the selected text.
Hope it works out.

very nice, ima try that fo sure

btw rightmouse copy paste doesnt work for as far as i know

Sunny13
12-03-2005, 10:13 AM
dijiyd
Is there any alternate method to fl.getDocumentDOM().clipPaste(); in actionscript itself to paste the copied contents from the clipboard. I know there isn't any predefined method/procedure for this but is it possible by any means? Explaing a bit more, using the right click menu, there is an option to paste the copied contents. So is there any command line alternative to the right click menu option.
Thanks

dijiyd
12-03-2005, 12:21 PM
I'm not sure, but I found this in the docs:
Note: Because of security concerns, it is not possible to read the contents of the system Clipboard. In other words, there is no corresponding System.getClipboard() method.

dprichard
12-05-2005, 11:04 AM
I thank everyone for their help. After realizing how difficult this turned out to be, the customer has decided to do away with this request. Thanks again. :)

dijiyd
12-06-2005, 09:18 AM
Oh, hey, sorry to revive, but I found something that might be of use related to this. Has anyone looked at the SharedObject class? It's like a "cookie" of sorts. I think you might be able to simulate the effect by doing the following:

for copy:
set the clipboard using System.setClipboard
Store it in a SharedObject

for paste:
retrieve it using SharedObject.

I don't have the time to detail on SharedObject right yet, I also learned of it just now.

Oops... sorry dprichard, I guess I was too late huh? :(

dprichard
12-06-2005, 10:05 AM
Thanks anyway friend! I will try that if this problem ever arises again.

Sunny13
12-07-2005, 03:09 AM
dijiyd
Could you please explain a bit more....if possible with an example.

Electric Dandy
12-07-2005, 04:40 AM
this action puts the selected text into a SO and copies it to the clipboard:

my_SO = SharedObject.getLocal("sharedInfo");
trace(my_SO.data.stickAround);
//
xFillSO = function (Data) {
my_SO = SharedObject.getLocal("sharedInfo");
my_SO.data.stickAround = Data;
nu_str = my_SO.data.stickAround;
if (nu_str != "") {
trace(nu_str);
}
};
_root.shared_txt.text = "share a lot";
language_SO.data.stickAround = "word";
//
var ch_num:Number = 0;
var nu_str:String = "";
// I'm using a RollOver, since a mousePress undoes the textSelection
_root.share_mc.onRollOver = function() {
nu_str = "";
begin_num = Selection.getBeginIndex();
end_num = Selection.getEndIndex();
total_num = end_num-begin_num;
for (i=0; i<total_num; ++i) {
nu_str += (_root.shared_txt.text.charAt(i+begin_num));
}
// put it into the SharedObject, to make it available at reload
xFillSO(nu_str);
// and copy it to the clipoard too.
System.setClipboard(nu_str);
// outside the swf file, a ctrl/cmd+paste will paste the selected text
// I don't know if this can be done automatically... maybe ASP? PHP? dunno...
};
The SharedObject is stored on the hardDisk of the user,
even twice if the file is local.
If needed it can be retreived with a search for "sharedInfo.sol"