Flex : button acting like a backspace

痞子三分冷 提交于 2019-12-11 09:57:10

问题


How would you make a button event call a function which acts like a backspace keyboard event delete.

I tried faking the dispatch keyboard event "keyup" "keydown" with keycode 8 and keynumber 8 without success.

No other way than doing it by hand with begin and end select index plus substr ?

I have a textinput i just want to add a button acting like a backspace.

Thanks


回答1:


You can use the ASCII code 8 and translate it to a char or use the escape character '\b'

or you can manipulate the textFieldInstance object:

textFieldInstance.text = textFieldInstance.text.substr( 0, -1 );

see:

http://board.flashkit.com/board/showthread.php?t=246003

http://www.java2s.com/Code/Flash-Flex-ActionScript/String/InsertingSpecialWhitespaceCharactersBackspaceb.htm

http://www.wipeout44.com/brain_food/flash_actionscript_goodies.asp

http://www.ultrashock.com/forums/actionscript/deleting-chars-in-a-text-field-e-g-backspace-124649.html




回答2:


You could try this:

function delSelected(textFieldInstance:TextField):void {
  var bIndex:int = textFieldInstance.selectionBeginIndex;
  var eIndex:int = textFieldInstance.selectionEndIndex;
  if (bIndex == eIndex) {
    textFieldInstance.text = textFieldInstance.text.substr(0,-1);
  } else {
    var a:String = textFieldInstance.text.substr(0,bIndex);
    var b:String = textFieldInstance.text.substr(eIndex);
    textFieldInstance.text = a+b;
  }
}


来源:https://stackoverflow.com/questions/1190813/flex-button-acting-like-a-backspace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!