Wild card character for text string?
Okay, this is a long shot, but it's worth posting, even if I get flamed for being a total newbie.
I'm interested in creating a v-e-r-y simple Question and Answer animation.
A user types a Question into an input textfield, and whatever phrase and words they type, if in it is contained the word "fired," my answer would be to go to frame label FIRED and Answer = "You are so fired."
Alternately, if it also contained the word "trouble", "late", "hate", (etc) it would still go to frame label FIRED and Answer = "You are so fired."
Else it would go to a generic answer or prompt for another question.
(I guess this is sort of like a magic eight ball meets subservientchicken...not 400 movie clips, but perhaps about answers relative to keywords typed)
Anyway, rather than set up an array, is there asimple wild card character for text strings? Like,
question = inputText
if (question == ("*"+"fired"+"*")) {
Answer = "You are so fired." ;
} else {
Answer = "You are on thin ice, ask again." ;
}
I realize this is a wish on my part (I have to publish in F6), perhaps to avoid massive arrays, functions, and math...but it's worth asking.
This type of animation quiz or Q&A must have been done before but I can't seem to find it.
Any suggestions?
Re: Wild card character for text string?
Quote:
Originally posted by lneuma1
Anyway, rather than set up an array, is there asimple wild card character for text strings?
No, flash isn't able to handle regular expressions on strings.
you could find out about a word contained in a string using String.indexOf().
just a quick sample (didn't test):
Code:
var findKeyword= function (txt:String, keywords:Array):Boolean {
for (var i:Number=keywords.length;i>=0;--i) {
if(txt.indexOf(" "+keywords[i]+" ")<>-1) {
return true;
}
}
return false;
}
//
var keywords:Array= new Array("fired", "trouble", "late", "hate");
var question:String="I am late";
if (findKeyword(question, keywords)) {
gotoAndPlay("fired");
} else {
gotoAndPlay("hired"):
}