-
I want to have a button that when clicked will search an array for a word that has been inputted to a text box by the user. Sort of like a spell checker.
I have tried searching this site (tutorials and forums) and have had no luck.
Someone suggested using a text file instead of an array but I have no idea on how to search a text file either.
I'm not new to Flash and I know the basics of Actionscript but I'm finding it very difficult to figure out how to do this and would appreciate some help on the matter.
Thanks.
-
If your array is called textArray, you can use the following. The variable 'myWord' is set to the string you are looking for:
Code:
for (j=0, j<=textArray.length, j++){
if (textArray[j] == myWord){
someFunction();
break;
}
}
hope this helps you
-
Hi,
if your text box is called text, try
Code:
if(text.indexOf('word') >= 0)
{ // word appears in text
}
if you have an array of words to look for,
Code:
wordlist = ['love', 'letter', 'virus']
for(i = 0 ; i < wordlist.length ; i++)
if(text.indexOf(wordlist[i]) >= 0)
{ // ok, found one
}
Dont expect flsh to be very efficient on that, so checking a long text may get you "running slow" alerts
Musicman
-
Thank you, it works great.
I'm glad I don't have that to bother about now.
The array is going to be quite big so that could pose a bit of a problem.
I'll see how it goes.
Thanks again.
-
Hi,
if both the array and the text get big, you should do a few words at a time in a frame loop - or if the words to check are fixed, you could use to a completely different approach where not a list of words is loaded into flash, but rather a table created from the list of words by a separate program
concept of frame loop
1st frame in loop:
ctr = 0;
end = wordlist.length;
2nd frame
Code:
for( ; ; )
{ if(text.indexOf(wordlist[ctr]) >= 0)
// found one
if(++ctr == end)
{ nextFrame();
break;
}
else if((ctr % 20) == 0)
{ prevFrame();
break;
}
}
Musicman
-
I might try it with seven arrays.
The game I'm making only allows you to make a words of 3 - 9 letters so I was going to make an array for each word length.
Hopefully that should make it less resource hogging.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|