Skip to main content
Inspiring
March 18, 2008
Answered

multiple text-input boxes and outString

  • March 18, 2008
  • 2 replies
  • 573 views


I have an text input box that the user types their name in. They click a button and the name is moved to a new box in the scene, where a happy birthday message also appears.
The first box's instance name is tb1, the second box's instance name is tb2.

this is the code so far:
btn_enter.onPress = function() {
outString = "Happy Birthday " + inString ;

What I need to do is to have another user type their name in the first box. After clicking the button, their name will move to the 2nd box, and the name that was in the 2nd box needs to go to a third box, so it doesn't disappear from the screen. How to approach this?
Do I create dynamic text boxes? Or more input boxes? What I'm currently doing isn't working (moving the text in box 2, to box 3) so I'm not sure what to do next...
Any suggestions are greatly appreciated!!!!
thank you.


This topic has been closed for replies.
Correct answer justice49
I have the solution and wanted to post it, in case others run into this problem. It was given to me by a poster named NumbFinger, on another site. It works perfectly!

//array that will store the usernames
var users:Array = new Array();
//variable that will get the text out of the input field
var newuser:String;
inputName.text = "Enter Name Here";
//attach addUser function to the button named inputButton
inputButton.addEventListener(MouseEvent.CLICK,addUser);
function addUser(Event:MouseEvent){
//get text from textfield named inputName
newuser = String(inputName.text);
//if users array is not empty, add the newuser to the front of the array
if(users.length>0){
users.splice(0,0,newuser);
//if it is empty, just add the first value to the array
}else{
users.push(newuser);
}
//if the values exist in the array, set each textfield (named user1, user2, and user3) equal to the proper value
if(users.length>0){user1.text = users[0];}else{user1.text = "";}
if(users.length>1){user2.text = users[1];}else{user2.text = "";}
if(users.length>2){user3.text = users[2];}else{user3.text = "";}
}

2 replies

justice49AuthorCorrect answer
Inspiring
March 19, 2008
I have the solution and wanted to post it, in case others run into this problem. It was given to me by a poster named NumbFinger, on another site. It works perfectly!

//array that will store the usernames
var users:Array = new Array();
//variable that will get the text out of the input field
var newuser:String;
inputName.text = "Enter Name Here";
//attach addUser function to the button named inputButton
inputButton.addEventListener(MouseEvent.CLICK,addUser);
function addUser(Event:MouseEvent){
//get text from textfield named inputName
newuser = String(inputName.text);
//if users array is not empty, add the newuser to the front of the array
if(users.length>0){
users.splice(0,0,newuser);
//if it is empty, just add the first value to the array
}else{
users.push(newuser);
}
//if the values exist in the array, set each textfield (named user1, user2, and user3) equal to the proper value
if(users.length>0){user1.text = users[0];}else{user1.text = "";}
if(users.length>1){user2.text = users[1];}else{user2.text = "";}
if(users.length>2){user3.text = users[2];}else{user3.text = "";}
}
Participating Frequently
July 19, 2022

I have another issue , completly diffrent one. Iam struggling to read the password enterted in dailogbox using starndered java script password read mechanisam on Mac.

 

Below is the snippet :

var dlg = new Window( windowResource);
dlg.group1.name.text = userName;
dlg.group1.password.active = true;
dlg.bottomGroup.applyButton.onClick = function ( ) { password = dlg.group1.password.text;;$.setenv("PW", password);this.parent.parent.close( 2 ); }
dlg.bottomGroup.cancelButton.onClick = function ( ) { cancelled = true; this.parent.parent.close( 2 ); }
dlg.show();

 

windowResource = "dialog {
orientation: 'column',
alignChildren: ['fill', 'top'],
preferredSize:[200, 130],
text: 'Login',
margins:15,

group1: Panel {
orientation: 'row',
alignChildren: 'right',
margins:15,
text: ' Login ',
st: StaticText { text: 'User ID:' },
name: EditText { text: '', characters: 25, justify: 'left'}
st3: StaticText { text: 'Password:' },
password: EditText { text: '', characters: 25, justify: 'left', properties: {noecho:'true'}}
}

bottomGroup: Group{
cancelButton: Button { text: 'Cancel', properties:{name:'cancel'}, size: [120,24], alignment:['right', 'center'] },
applyButton: Button { text: 'Apply', properties:{name:'ok'}, size: [120,24], alignment:['right', 'center'] },
}
}

Participating Frequently
July 19, 2022

dlg.group1.password.text; is always coming as empty string.

Damon Edwards
Inspiring
March 18, 2008
First, this obviously isn't an AS3 question because 'onPress' handlers aren't supported anymore. Second, you can use an if statement to determine if there is text in the 2nd box already, if there is, set the 3rd box's text property equal to the 2nd.