• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

Copy selected text to system clipboard in actionscript 2

Hi, I would like to be able to copy a selection from a text box (txtContent)  to the system clipboard in flash

I can easily get  text on to the clipboards using: System.setClipboard(txtContent);

And I think I can get the position of the selection like this: Selection.getBeginIndex() and Selection.getEndIndex();

But here is where i got lost!
      

0
tomdenton
Asked:
tomdenton
  • 3
3 Solutions
 
tomdentonAuthor Commented:
Just answered my own question I think! :-)

Suggestions for improvements welcome


var selectStart:Number = Selection.getBeginIndex();
	var selectEnd:Number = Selection.getEndIndex();
	if (selectStart != txtContent.selectEnd){
		var selectedText:String = txtContent.text.slice(selectStart, selectEnd);
		System.setClipboard(selectedText);
	}

Open in new window

0
 
quizengineCommented:
I haven't tried your code, but I thought I would share some info about some security changes in Flash Player 10.

In response to 'click jacking' (nefarious swfs that captured stuff to the clipboard without the user's knowledge) Adobe made certain fuctions, including capturing text to the clipboard, a function that could *only* be achieved with a user interaction. This may mean that you will have to attach your script to a button, rather than just have it run when you want.

See here for more details - http://www.adobe.com/devnet/flashplayer/articles/fplayer10_uia_requirements.html
0
 
tomdentonAuthor Commented:
A sensible precaution too - I do have it as a button as it happens, but thanks for the info and the advice.

The code below works fine.
on (release);
    var selectStart:Number = Selection.getBeginIndex();
    var selectEnd:Number = Selection.getEndIndex();
    if (selectStart != selectEnd){
	var selectedText:String = txtContent.text.slice(selectStart, selectEnd);
	System.setClipboard(selectedText);
    }
}

Open in new window

0
 
tomdentonAuthor Commented:
Developed the answer myself in this case - shows how much we learn and appreciate the help from experts
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now