如何防止AS3自动添加换行符?

发布于 2025-01-04 08:55:24 字数 726 浏览 4 评论 0原文

我对特定字符串变量有疑问。它会自动在字符串“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

居里长安 2025-01-11 08:55:24

确保您的文本字段的属性是单行而不是多行。

如果这不起作用,您还可以尝试以下方法:
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), "")

傲娇萝莉攻 2025-01-11 08:55:24

您是否尝试过将结束行和回车符分开?

characterName = characterName.split("\n").join("");
characterName = characterName.split("\r").join("");

Have you tried separating the end-line and the carriage return?

characterName = characterName.split("\n").join("");
characterName = characterName.split("\r").join("");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文