如何防止AS3自动添加换行符?
我对特定字符串变量有疑问。它会自动在字符串“characterName”中的文本后面添加换行符。在此框架上,我有一个实例名称为 name_Input 的输入文本框和一个执行以下代码的提交按钮。
var characterName:String;
characterName = name_Input.text;
//The next line was a solution I tried for this problem but it doesn't work
characterName = characterName.split("\r\n").join("");
nextFrame();
在下一帧上,有一条跟踪可以查看该变量加上另一个变量的值。
trace(characterName+", the "+characterClass);
characterClass 自动定义为“默认”,因此我可以查看它是否正常工作。 跟踪显示以下内容:
"Name
, the Default"
如果有人可以帮助我弄清楚为什么换行符不断出现以及如何防止这种情况,我将不胜感激。
另外,如果我在文本框中键入“名称”之前按删除键,它会按行显示。很明显,盒子里自动有一个换行符。我已经尝试删除并重新制作文本框,以确保我没有意外地向其中添加了某些内容。
提前致谢。
I have an issue with a specific string variable. It is automatically adding a line break after the text in the string characterName. On this frame I have a input text box with an instance name of name_Input and a submit button that executes the following code.
var characterName:String;
characterName = name_Input.text;
//The next line was a solution I tried for this problem but it doesn't work
characterName = characterName.split("\r\n").join("");
nextFrame();
And on the next frame there is a trace to see what the value of that plus another variable is.
trace(characterName+", the "+characterClass);
characterClass is automatically defined as "Default" so I can see if it worked properly.
The trace is displaying the following:
"Name
, the Default"
If anyone can help me figure out why the line break keeps showing up and how to prevent this, I would greatly appreciate it.
Also, if I hit the delete key before typing "Name" in the text box, it displays in line. So clearly the box has a line break in it automatically. I've already tried deleting and remaking the text box to make sure I hadn't accidentally added something to it.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您的文本字段的属性是单行而不是多行。
如果这不起作用,您还可以尝试以下方法:
yourstring.replace(String.fromCharCode(13), "")
Make sure your Text Field is Single Line and not Multi Line in it's properties.
If that doesn't work, you can also try something like:
yourstring.replace(String.fromCharCode(13), "")
您是否尝试过将结束行和回车符分开?
Have you tried separating the end-line and the carriage return?