A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: Subservient Chicken

Threaded View

  1. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    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;
    }
    }
    }
    }

    Last edited by jbum; 10-15-2004 at 05:27 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center