Copy link to clipboard
Copied
i m trying to make a hangman style game.i have 33 dynamic text fields on my stage like this.
i have parsed all text fields row by row into 3 arrays.
i also parsed my 3 words into 3 arrays with split method so i can check later if the letter that the user picked exists.
in next frame when the game begins and the user picks a letter although i can check if the letter exist in my first word array i cant display it on current textfield on my stage.
i get the following error:ReferenceError: Error #1056: Cannot create property text on String.
i guess when i parsed the textfields in arrays they automatically got strings.And i cant do this for example:
firstwordarray is the array where i parsed my first word with split method.
letterchosentxt is the textfield where the user picks a letter.
firstarray is the array where i parsed the first row(11) of text fields.
for(var p:uint=0;p<firstwordarray.length;p++)
{
if(letterchosentxt.text==firstwordarray
)
{
firstarray
.text=letterchosentxt.text;
break;
}
}
thanks in advance.
yes, because you are not assigning the textfields but only their text property (these are two different things)
however you could put a textfield named "textfield1" into an array
either with:
array.push(textfield1)
or with
array[0] = textfield1
its important to mention that putting a displayobject into an array doesn`t do anything visibly to the displayobject but only provides a method to easily reference it.
Copy link to clipboard
Copied
just write
firstarray
=letterchosentxt.text;
Copy link to clipboard
Copied
I have done it..if I trace it is there but it doesn't display on screen.
Copy link to clipboard
Copied
Make sure that you embed whatever font you are using in your dynamic textfields and that you use a small enough font that it will actually show something.
Copy link to clipboard
Copied
The size of text fields is OK.the font size is OK.I have embed all the fonts I am using .the real problem i think is the error I get:cannot create property text on string.
Copy link to clipboard
Copied
cannot create property text on string.
Make sure that you have a Array filled with TextFields not with Strings.
An easy method to grab all TextFields from your stage is sth like.
var textField_array:Array = [];
//loop through all DisplyObjects on stage and add them to an array if they are TextFields
for (var i:int = 0; i<stage.numChildren;i++){
if(getChildAt(i) is TextField){
textField_array.push(getChildAt(i));
}
}
//later on you can then set the Text property the way you intend
textField_array[4].text = "A"
//etc.
Copy link to clipboard
Copied
I will try it and I will tell you.if I assign the text fields one by one into an array is wrong? Like this:
first array[0]=letter1txt.text;
Copy link to clipboard
Copied
yes, because you are not assigning the textfields but only their text property (these are two different things)
however you could put a textfield named "textfield1" into an array
either with:
array.push(textfield1)
or with
array[0] = textfield1
its important to mention that putting a displayobject into an array doesn`t do anything visibly to the displayobject but only provides a method to easily reference it.
Copy link to clipboard
Copied
Yes but if I do this
Firstarray[0]=textfield1;
When later in the same frame I want to display something in
Textfield1.text I cant do this
first array[0].text= letterchosen.text;
So firstarray [ ] has strings inside it.because of the error I get.
Copy link to clipboard
Copied
Start a new fresh as3 file.
put a dynaimc TextField on stage and name it "tf1"
write:
tf1.text = "Hello"
compile it, it should show "Hello" if you properly embedded your fonts.
now
add the following:
var arr:Array = new Array();
arr.push(tf1);
arr[0].text = "World"
compile it, it should show "World" if you properly embedded your fonts.
now add the following:
var str:Array= new Array()
str.push(tf1.text);
trace(str[0])
//traces World
trace(str[0].text)
//throws Error #1056: Cannot create property text on String.
Hopefully that cleared things up for you
Copy link to clipboard
Copied
ok i got it now.Thanks a lot for the help!