One way to do it would be to have a movieclip that contains a number of different sections, each with a different label. When you issue
gotoAndPlay('dance');
or
gotoAndPlay('jump');
It will jump to the appropriate label. At the end of the section there is a script that says
gotoAndPlay('idle');
which jumps to back to a basic idle loop.
To process the text, you can do something like:
code:
myTextInput.onChanged = function()
{
if (this.text.indexOf('dance') >= 0)
{
// text contains the word 'dance'
gotoAndPlay('dance');
}
else if (this.text.indexOf('jump') >= 0)
{
// text contains the word 'jump'
gotoAndPlay('jump');
}
else if (this.text.indexOf('make poptarts') >= 0)
{
// text contains the words 'make poptarts'
gotoAndPlay('make poptarts');
}
// etc.
}
Alternately, you can use a data structure for all your triggers and labels, enabling you to more easily define multiple triggers for each clip.
code:
myTriggers = [ { trigs: ['poptarts','breakfast'], label: 'poptarts'},
{ trigs: ['dance','boogie'], label: 'dance'},
{ trigs: ['jump','hop'], label: 'jump'}];
myInput.onChanged = function()
{
for (var i = 0; i < myTriggers.length; ++i)
{
for (j = 0; j < myTriggers[i].trigs.length; ++j) {
if (this.text.indexOf(myTriggers[i].trigs[j]) >= 0)
{
gotoAndPlay(myTriggers[i].label);
return;
}
}
}
}




Reply With Quote