From b4110a682088919a65408f298930af2c1750d612 Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Wed, 14 Oct 2009 20:53:29 -0700 Subject: [PATCH] add text selection test script --- doc/examples/textselect.sc | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 doc/examples/textselect.sc diff --git a/doc/examples/textselect.sc b/doc/examples/textselect.sc new file mode 100644 index 0000000..59cc104 --- /dev/null +++ b/doc/examples/textselect.sc @@ -0,0 +1,63 @@ +.flash version=6 + + .font Arial "../doc/Arial.swf" + .edittext et width=600 height=50 color=black font=Arial size=40pt border text=test variable=text_selection + + .frame 1 + + .swf TextBox document.swf + .put TextBox + .put et x=10 y=10 + + .frame 2 + + .action: + str = TextBox.getTextSnapShot(); + str.setSelectColor(0xffff00); + firstChar = -1; + + TextBox.onMouseDown = function() { + firstChar = str.hitTestTextNearPos(_xmouse, _ymouse, 0); + str.setSelected(0, str.getCount(), false); + _root.text_selection = str.getSelectedText(true); + }; + + TextBox.onMouseUp = function() { + if (firstChar >= 0) { + lastChar = str.hitTestTextNearPos(_xmouse, _ymouse, 0); + if (firstChar != lastChar) { + if (firstChar < lastChar) { + str.setSelected(firstChar, lastChar+1, true); + _root.text_selection = str.getSelectedText(true); + } else { + str.setSelected(lastChar, firstChar+1, true); + } + } + _root.text_selection = str.getSelectedText(true); + firstChar = -1; + lastChar = -1; + } + }; + + TextBox.onMouseMove = function() { + if(firstChar != -1) { + str.setSelected(0, str.getCount(), false); //unselect everything + + lastChar = str.hitTestTextNearPos(_xmouse, _ymouse, 0); + if (firstChar < lastChar) { + str.setSelected(firstChar, lastChar+1, true); + } else if(lastChar >= 0) { + str.setSelected(lastChar, firstChar+1, true); + } + _root.text_selection = str.getSelectedText(true); + } + }; + .end + + .frame 3 + .action: + Stop(); + .end + +.end + -- 1.7.10.4