使用箭头浏览actionscript swf的最佳方法是什么?
答案 0 :(得分:0)
设置tabIndex
的{{1}}属性。这应该允许您在表单中进行制表。
不建议覆盖箭头键的默认功能,因为它们用于在textInput中移动文本插入点
至于enter,您必须侦听keyUp事件,如果检测到回车键,则移至下一个字段。
TextInput
修改强>
对于Flash CS5,此代码应该有效:
//add this eventlistener for each textbox (through a loop or manually)
t.addEventListener(KeyboardEvent.KEY_UP, k);
//The event handler
protected function k(e:KeyboardEvent):void {
if(e.keyCode==Keyboard.ENTER) {
focusManager.getNextFocusManagerComponent().setFocus();
}
}
重要:首先将组件从“用户界面”组拖到舞台上并将其删除。这应该将库中所有必需的组件准备好供您使用
<强> EDIT2 强>
更改
import flash.events.KeyboardEvent;
import fl.managers.FocusManager;
import flash.display.InteractiveObject;
import fl.managers.IFocusManagerComponent;
import fl.managers.IFocusManager;
t1.addEventListener(KeyboardEvent.KEY_UP, k);
t1.tabIndex=1;
t2.tabIndex=2;
var fm:FocusManager=new FocusManager(this);
t1.tabEnabled=true;
t2.tabEnabled=true;
function k(e:KeyboardEvent):void {
if(e.keyCode==Keyboard.ENTER) {
var fx:InteractiveObject = fm.getNextFocusManagerComponent();
fm.setFocus(fx);
}
}
在您的代码中:
for(var i:int=0; i < textbox.length; i++) {
//textbox[i].buttonMode = true;
//box[i].addEventListener(MouseEvent.CLICK, myclick_ftn);
//box[i].addEventListener(FocusEvent.FOCUS_IN,textInputHandler);
//box[i].addEventListener(FocusEvent.FOCUS_OUT,textInputHandlerOut);
textbox[i].restrict = "0-9";
textbox[i].addEventListener(KeyboardEvent.KEY_UP, k);
textbox[i].tabIndex=i;
//t2.tabIndex=2;
//textbox[i].tabEnabled=true;
var fm:FocusManager=new FocusManager(this);
function k(e:KeyboardEvent):void {
if(e.keyCode==Keyboard.ENTER) {
var fx:InteractiveObject = fm.getNextFocusManagerComponent();
fm.setFocus(fx);
}
}
//t2.tabEnabled=true;
}