Real single line TextField??

  Real single line TextField??
You create a TextField with multiline = false, and then publish it, well, you think the textfield just accept single line text, you press Enter, no newline entered, you paste a new line, it is filtered. Seems every thing runs well...

真正单行TextField(文本框)??
你建立一个TextField(译者注:最好把高度调高一些,这样效果明显),设置属性multiline = false,然后发布。现在你觉得这个TextField只接受单行文本,你按回车键。没有新的行加入,你粘贴想显示出新的一行,但是被过滤了。看起来一切正常。


But how about when you press Ctrl+Enter when your swf runs in Internet Explorer? On my machie, new line is entered, the single line textfield became a two line textfield.(Tested on Windows2000+IE6+FP8 plugin)

但是,当你的FLASH运行在一个IE窗口里,你输入Ctrl+Enter,会怎么样呢?在我的机器上,一个新行被加入了,这个单行textfield,变成了两行的textfield。(测试环境:Windows2000+IE6+FP8 plugin)(译者注:经测试在使用IE内核的浏览器都有这现象,而Firefox浏览器则没有。)

This is weird and annoying, but here is a solution:
Add a handler to the onScroller event, when your single line textfield scrolled, means newline is entered, then you can find out the newline code and deleted it from your textfield text, sample code:

这个现象非常奇怪也非常烦人。但是这里有一个解决办法:在onScroller事件上加一个事件处理函数,当你的单行textfield的scroll属性变化时就意味着有一个新行加入了,然后你就可以找出这个新行然后从你的textfield中删除,代码:

yourTextField.onScroller = function(textField:TextField){
var str:String = textField.text;
    //only check it when Ctrl or Enter pressed
if(Key.getCode() == Key.CONTROL || Key.getCode() == Key.ENTER){
  for(var i:Number=0; i<str.length; i++){
   if(str.charCodeAt(i) == 13){
    textField.text = str.substring(0, i) + str.substring(i+1);
    return;
   }
  }
}
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值