0

I am trying to make a program combine two strings to make a name...

My code is

function addStudent(evt: MouseEvent)
{
var tempFirst = newStudent.firstName.text;
var tempLast = newStudent.lastName.text;
var tempStartDate = String(newStudent.startDate.text);
var tempBirthDate = String(newStudent.birthDate.text);
numStudents++;

var tempName = newStudent.firstName.text + newStudent.lastName.text;
trace(tempName);

studentList.dataProvider.addItem({label: tempName, data: tempName});

var tempStudent:student = new student(tempFirst, tempLast, tempStartDate, tempBirthDate);

studentHolder.addChild(tempStudent);

listStudents();
}

what the trace returns (if I input Jack Rob) is:

Jack
Rob

instead of JackRob

newStudent.firstName.text points to a movie clip called newStudent, with an input box called firstName

I have tried:

var tempFirst = String(newStudent.firstName.text);
var tempLast = String(newStudent.lastName.text);

var tempName = newStudent.firstName.text + newStudent.lastName.text;
var tempName = (newStudent.firstName.text).concat(newStudent.lastName.text);
var tempName = String(newStudent.firstName.text) + String(newStudent.lastName.text);

most of those were just me grasping at straws and hoping maybe something would work

essentially the goal is for the user to input a first and last name, and that first and last name is inputted into the dataProvider as one single string (JackRob)

I appreciate any help anyone can give, thank you in advance

4

1 回答 1

0

我相信您在 TextField 中的字符串末尾有一个不可见的回车。尝试这个 :

var tempFirst.replace(String.fromCharCode(13), "");

如果这行得通,那么情况确实如此。

我相信当您使用多行文本字段时会发生这种情况。在 Flash IDE 的 TextField 属性面板上将其设置为单行 TextField 或使用以下代码:

newStudent.firstName.multiline = false;
于 2013-04-21T22:42:53.407 回答