使用9个button作为数字按钮(1~9),用两个textfield为身份证号码和手机号输入框
布局:
----------------------------------
输入框1:______ 1 2 3 |
输入框2:______ 4 5 6 |
7 8 9 |
-----------------------------------
实现功能:点击右边数字键,能够正确的往当前焦点所在输入框数字
问题:当点击右边1、2、3,按正常情况光标应该紧跟在123之后:如123|,但是经常会出现光标不正常跳动情况:12|3,或者1|234这样的情况(注|代表光标),
问应该怎么样才能确保光标正常跳动?
/var mobileInput:TextField = new TextField();
//var idInput:TextField = new TextField();
_currInput=mobileInput;
var haveFocus:Boolean = false;
mobileInput.onSetFocus = function ()
{
_currInput=mobileInput;
haveFocus = true;
};
mobileInput.onKillFocus = function():Void {
haveFocus = false;
};
idInput.onSetFocus = function () {
_currInput= idInput;
haveFocus = true;
};
idInput.onKillFocus = function():Void {
haveFocus = false;
};
var BIndex:Number = 0;
var EIndex:Number = 0;
this.onEnterFrame = function():Void {
if (haveFocus) {
BIndex = Math.max(0, Selection.getBeginIndex());
EIndex = Math.max(0, Selection.getEndIndex());
}
};
btn0.onRelease = function():Void { addNum("0"); };
btn1.onRelease = function():Void { addNum("1"); };
btn2.onRelease = function():Void { addNum("2"); };
btn3.onRelease = function():Void { addNum("3"); };
btn4.onRelease = function():Void { addNum("4"); };
btn5.onRelease = function():Void { addNum("5"); };
btn6.onRelease = function():Void { addNum("6"); };
btn7.onRelease = function():Void { addNum("7"); };
btn8.onRelease = function():Void { addNum("8"); };
btn9.onRelease = function():Void { addNum("9"); };
btnBackspace.onRelease = function():Void { Backspace(); };
btnClear.onRelease = function():Void { Clear(); };
btnCancel.onRelease = function():Void { Clear(); };
function addNum(insertText)
{
// _currInput.setFocus();
import mx.controls.Alert;
if (_currInput==mobileInput)
{
if (_currInput.text.length==11)
{
Alert.show("手机号码长度只能是11位","提示信息");
return;
}
}
if (_currInput==idInput)
{
if (_currInput.text.length==18)
{
Alert.show("身份证号码最长只能是18位","提示信息");
return;
}
}
_currInput.text = _currInput.text.substr(0, BIndex)+insertText+_currInput.text.slice(EIndex);
// _currInput.text = _currInput.text.substr(0,BIndex)+_currInput.text.substr(BIndex,EIndex)+insertText;
//_currInput.text += insertText.toString();
//Alert.show(_currInput.getCaretIndex);
//Selection.setSelection( BIndex+insertText.length, BIndex+insertText.length);
//Selection.setSelection( BIndex+insertText.length, BIndex+insertText.length);
//Selection.setSelection( BIndex+1, BIndex+1);
//Selection.setFocus("btn"+insertText.toString());
//Selection.setFocus(null);
//Selection.setFocus(_currInput);
//Selection.setSelection( _currInput.text.length+1, _currInput.text.length+1);
//Selection.setFocus("btn"+insertText.toString());
//Selection.setFocus(null);
/* inputListener = new Object();
inputListener. = function(eventObject){
Selection.setFocus(_currInput);
Selection.setSelection(_currInput.text.length+1, _currInput.text.length+1);
}
_currInput.addEventListener("focusOut", inputListener)
*/
Selection.setFocus(_currInput);
Selection.setSelection(_currInput.text.length, _currInput.text.length);
}
function Backspace()
{
_currInput.text = _currInput.text.substr(0, BIndex-1)+_currInput.text.substr(BIndex,EIndex);
Selection.setFocus(_currInput);
Selection.setSelection( BIndex-1, BIndex-1);
}
function Clear()
{
_currInput.text ="";
}
对flash的as不熟悉,弄了一周都没什么进展啊,那位高人能指点一下在下,在下感激不尽。。。。。。