forked from: TextField_URLLoader
forked from TextField_URLLoader (diff: 49)
ActionScript3 source code
/**
* Copyright hacker_9p8x8mco ( http://wonderfl.net/user/hacker_9p8x8mco )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/7aGp
*/
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldType;
public class TextField_caretIndex extends Sprite {
public function TextField_caretIndex() {
var tf:TextField = createTextField(10, 10, 100, 100);
tf.wordWrap = true;
tf.type = TextFieldType.INPUT;
tf.text = "Click in this text field. Compare the difference between clicking without selecting versus clicking and selecting text.";
tf.addEventListener(MouseEvent.CLICK, printCursorPosition);
}
private function printCursorPosition(event:MouseEvent):void {
var tf:TextField = TextField(event.target);
trace("caretIndex:", tf.caretIndex);
trace("selectionBeginIndex:", tf.selectionBeginIndex);
trace("selectionEndIndex:", tf.selectionEndIndex);
}
private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
var result:TextField = new TextField();
result.x = x;
result.y = y;
result.width = width;
result.height = height;
addChild(result);
return result;
}
}
}
