Groups | Blog | Home
all groups > flash (macromedia) > july 2005 >

flash (macromedia) : Help me plz: save characters


kamyarabhari
7/10/2005 9:16:55 PM
There is an input text which user enter a word in: for example: "Hello", I need
to save all characters in different variables:
in this case: str_1 = "H", str_2 = "e", str_3= "l" and so on...
Help me please, I don't know how I can do that. ( I tried getTextString() and
trace variable but it reteurns "undefined" :( )
Khan_Bali
7/10/2005 11:55:11 PM
hi ... lookz like i have a possible solution
try this code

var userName:String = new String ();
var i:Number = 0;
name_txt.onChanged = function () {
userName = name_txt.text;
while (i < names.length) {
_root["str_" + i] = names.substr (i, 1);
i++;
}
};

name_txt is the instance name of your textfield
names is the string that i have created.
this should work ... ive tried it and found it working .....
when testing the movie, write some thing in the text field and goto the debug
menu and select list variables ... you should be able to see the variables
created.
kamyarabhari
7/11/2005 12:00:00 AM
kamyarabhari
7/11/2005 12:45:48 AM
Rothrock
7/11/2005 1:14:09 AM
Here is something even easier. Instead of putting the different letters into
different variables, put them in an array. An array is kind of like a set of
boxes with a box to hold each element you want to put in it. It is a nice tidy
way to keep track of things that belong together.

name_txt.onChanged=function(){
myArray= new Array();
myArray=name_txt.text.split("");
}

Then if you needed to know how many letters were in the word.

trace(myArray.length);

Of if you needed the third letter:

trace(myArray[2]);

Notice that to get the third thing you ask for 2, because arrays start with
zero not one.
AddThis Social Bookmark Button