Skip to main content
Inspiring
November 15, 2007
Question

extract first letter from input text

  • November 15, 2007
  • 9 replies
  • 541 views
how can i extract first letter from input text to achieve something like this:

input text:
name: (Jhon)
surname: (Rambo)

dynamic output:
Hello J.Rambo !


_root.onEnterFrame = function () {

letter = name - xxxxxxxxxxxxxxxxxxxxxxxxx?

out =
"Hello " + letter + "." + surname + " !"
};

what code should i put in xxxxxxxxxxxxxxxxxxxxxxx?

thank you.
This topic has been closed for replies.

9 replies

Inspiring
November 17, 2007
you're welcome
gin3dAuthor
Inspiring
November 17, 2007
works - GWD -thanks a lot!

Inspiring
November 16, 2007
What exactly are you trying to do, and what are the names of the textfields? Let's start again with that.

I think what you want to do is have a second dynamic textfield show the first letter of whatever is typed in the first, right?

If you have two textfields

Input textfield, instance Name: myName
Dynamic textfield, instance Name: dynamout

then all you need in the frame code is this:
myName.onChanged = function() {
dynamout.text=this.text.substr(0,1);
}


Inspiring
November 15, 2007
is dynamout another textfield? If yes:
dynamout.text=letter

gin3dAuthor
Inspiring
November 16, 2007
yes it feeds dynamic text field. whatever i try its undefined.
gin3dAuthor
Inspiring
November 15, 2007
this doesnt work:
input text instance named: input
dymaic text instance named: dynamout.
what im doing wrong?


_root.onEnterFrame = function () {

letter = input.text.substr(0,1);
dynamout = letter;

};

//output: undefined
gin3dAuthor
Inspiring
November 15, 2007
this works:
nam = "rembo";

_root.onEnterFrame = function () {
letter = nam.substr(0,1);
dynamout = letter;

};
// output: r
Inspiring
November 15, 2007
how are you getting your input text.

if its the old style and 'name' is a variable associated with an input text field ( I don't use this) then it should work, so long as name is not being used as a variable somewhere else.

if your input field instance is called name, then you need to use
letter = name.text.substr(0,1);
gin3dAuthor
Inspiring
November 15, 2007
thanks, but doesnt seems to work with input txt
Inspiring
November 15, 2007
letter = name.substr(0,1);

or

letter =name.split("")[0];