Actionscript 3 用setSelection控制as3中的克拉
好吧,我花了一些时间,并想出了我的惊喜。 不幸的是,我不能只用标准的箭头键。我正在做一个标签制造商的模拟器,它必须按照字母、箭头键和所有东西工作Actionscript 3 用setSelection控制as3中的克拉,actionscript-3,flash,text,Actionscript 3,Flash,Text,好吧,我花了一些时间,并想出了我的惊喜。 不幸的是,我不能只用标准的箭头键。我正在做一个标签制造商的模拟器,它必须按照字母、箭头键和所有东西工作 var boop = textSelect.text.length; var snoop = boop; bbbutton.addEventListener(MouseEvent.CLICK, backBtns); function backBtns(event:MouseEvent):void { snoop -= 1; st
var boop = textSelect.text.length;
var snoop = boop;
bbbutton.addEventListener(MouseEvent.CLICK, backBtns);
function backBtns(event:MouseEvent):void
{
snoop -= 1;
stage.focus = textSelect;
textSelect.setSelection( snoop,snoop);
}
您可以通过使用textField的
caretIndex
属性来实现这一点
假设textSelect
是TextInput
组件,如果它是textField
,只需从下面几行中删除.textField属性即可
//this gets the current caret position, and subtracts one (if not already at 0)
var pos:int = textSelect.textField.caretIndex > 0 ? textSelect.textField.caretIndex - 1 : 0;
//this sets the selection to adjusted caret postion
textSelect.setSelection(pos,pos);
此代码将始终将其设置为文本的结尾。左箭头和右箭头的默认行为不适合您吗?