00:00
00:00
Newgrounds Background Image Theme

Slanoth just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Character Name Entry As3

414 Views | 5 Replies
New Topic Respond to this Topic

Character Name Entry As3 2013-11-25 04:07:38


Hey, Newgrounds.
I haven't been 'round these here parts in a long time, but I recently started developing a flash game and everything was going swimmingly. I have random enemy generation down, a full on options menu with a lot of variables to control what you encounter within the game, and the story pretty planned out

Only one problem. I can't get the name entry for the character down. I have a text field and you can type in it and converts its contents to a string to be stored for later use in the game, but it keeps adding an extra line to the string. Making it kind of useless to use in dynamic text. This is the code I have.

function Submit(ev:MouseEvent):void
{
Input.toString()
myText = Input.text
trace(myText)
}

Basically, when the "Submit" button is clicked, this function begins. The Text Field (Instance Name "Input") is converted to a string and myText is a string that becomes equal to that input. The next step, I have the script output the contents of myText. This would be fine, far as I can tell except it adds an additional line beneath.

For example, if I put the name "Bill" in the box and click the submit button, it actually outputs:
Bill
(Extra Line here)

If I click the submit button again:
Bill
(Extra Line)
(Extra Line)

I can't see that working out for whenever I call that string to be used in a dynamic text. Any ideas of how I can fix it up?

Response to Character Name Entry As3 2013-11-25 04:26:57


Try myTextField.multiline = false;

Otherwise you can just strip all new lines out of a string with myString.split("\n").join("'");


If ya have something to say, PM me. I have a lot of time to spare.

Also never PM egg82.

BBS Signature

Response to Character Name Entry As3 2013-11-29 06:27:18


At 11/25/13 04:26 AM, MintPaw wrote: Try myTextField.multiline = false;

Otherwise you can just strip all new lines out of a string with myString.split("\n").join("'");

Well... The first line you told me did make a difference. But I am not sure it kept it from going multiline. Right now My String looks like
Frank
Frank
*Extra Line*

I will be googling around on the second thing you told me to do. Thanks for the help.

Response to Character Name Entry As3 2013-11-29 23:00:42


At 11/29/13 06:27 AM, PhoxSillanpaa wrote: I will be googling around on the second thing you told me to do. Thanks for the help.

What are you going to google? Mintpaw gave you a piece of code. How can you google pieces of code? What do you expect to find, if you google AS code?

Just add that line to your code

function Submit(ev:MouseEvent):void
{
  Input.toString()
  myText = Input.text
  myText=myText.split("\n").join("'"); //this piece of code is given by Mintpaw
  Input.text=myText;
  trace(myText)
}

Character Name Entry As3

Response to Character Name Entry As3 2013-11-29 23:50:53


Input.toString()

Um.....

Response to Character Name Entry As3 2013-11-30 03:26:51


At 11/29/13 11:50 PM, slugrail wrote: Input.toString()

Um.....

I understand. But let's not confuse the OP. He's already overburdened with information.
Let's say, if it works, and does not produce errors, then it's safe to keep it. Because if you change it, everything *might* get messed up.
No-no-no, don't look at me. I'm just explaining the logic that OP may have followed when he added that line.