AS3:setSelection向上箭头覆盖 [英] AS3: setSelection Up Arrow Override
本文介绍了AS3:setSelection向上箭头覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想专注于文本字段结束的时候向上箭头是pssed $ P $。我使用的:
I would like to focus on the end of a TextField when the up arrow is pressed. I'm using:
txt.setSelection(txt.text.length,txt.text.length);
这对于除向上箭头任意键的伟大工程。我认为,向上的箭头自动设置选择到TextField的开始,当它在焦点。我怎么能覆盖此默认行为?
This works great for any key except the up arrow. I believe that the up arrow automatically sets selection to the beginning of a TextField when it is in focus. How can I override this default behaviour?
推荐答案
我想改变的home键的行为,这是我做的:
(以下code应该基本上是关闭的HOME键,但可以进行修改,以使其做任何事情)
I wanted to change the behavior of the home key, this is how I did it :
(The following code should essentially disable the HOME key but can be modified to make it do anything)
// Create two variables two remember the TextField's selection
// so that it can be restored later. These varaibles correspong
// to TextField.selectionBeginIndex and TextField.selectionEndIndex
var overrideSelectionBeginIndex:int = -1;
var overrideSelectionEndIndex:int;
// Create a KEY_DOWN listener to intercept the event ->
// (Assuming that you have a TextField named 'input')
input.addEventListener(KeyboardEvent.KEY_DOWN, event_inputKeyDown, false, 0, true);
function event_inputKeyDown(event:KeyboardEvent):void{
if(event.keyCode == Keyboard.HOME){
if(overrideSelectionBeginIndex == -1){
stage.addEventListener(Event.RENDER, event_inputOverrideKeyDown, false, 0, true);
stage.invalidate();
}
// At this point the variables 'overrideSelectionBeginIndex'
// and 'overrideSelectionEndIndex' could be set to whatever
// you want but for this example they just store the
// input's selection before the home key changes it.
overrideSelectionBeginIndex = input.selectionBeginIndex;
overrideSelectionEndIndex = input.selectionEndIndex;
}
}
// Create a function that will be called after the key is
// pressed to override it's behavior
function event_inputOverrideKeyDown(event:Event):void{
// Restore the selection
input.setSelection(overrideSelectionBeginIndex, overrideSelectionEndIndex);
// Clean up
stage.removeEventListener(Event.RENDER, event_inputOverrideKeyDown);
overrideSelectionBeginIndex = -1;
overrideSelectionEndIndex = -1;
}
这篇关于AS3:setSelection向上箭头覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文