From: Matthias Kramm Date: Thu, 15 Oct 2009 03:53:29 +0000 (-0700) Subject: add text selection test script X-Git-Tag: version-0-9-1~257 X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=commitdiff_plain;h=b4110a682088919a65408f298930af2c1750d612 add text selection test script --- 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 +