-1

I'm animating a mouth with microphone input. I'm using the microphone activity level, which delivers numbers from about 0-10. Each number corresponds to the frames in a "mouth" movie clip, so the louder the signal, the wider the mouth opens.

The mic activity level returns a value constantly (probably works out to once every frame). So even when the level stays the same for a while (particularly at 0 when there's no noise), it keeps executing the code to go to that frame.

I want to have the code execute only when the number changes.

import flash.display.BitmapData;
import flash.display.Shape;


var myMic:Microphone = Microphone.getMicrophone();
//Security.showSettings(SecurityPanel.MICROPHONE);
myMic.setLoopBack(true);
myMic.setUseEchoSuppression(true);


stage.addEventListener(Event.ENTER_FRAME, stage_EnterFrame);

function stage_EnterFrame(e:Event){
    var num:Number = myMic.activityLevel * 1;
    trace(num);
    if (num == 0){
        mouth.gotoAndStop(1);
    } else if (num == 1){
        mouth.gotoAndStop(2);
    } else if (num == 2){
        mouth.gotoAndStop(3);
    } else if (num == 3){
        mouth.gotoAndStop(4);
    } else if (num == 4){
        mouth.gotoAndStop(5);
    } else if (num == 5){
        mouth.gotoAndStop(6);
    } else if (num == 6){
        mouth.gotoAndStop(7);
    } else if (num == 7){
        mouth.gotoAndStop(8);
    } else if (num == 8){
        mouth.gotoAndStop(9);
    } else if (num == 9){
        mouth.gotoAndStop(10);
    } else if (num == 10){
        mouth.gotoAndStop(11);
    }
}

1 Answers1

1

So only exicute if it changes? Maybe something like

newNum=mic.activityLevel

If newNum != oldNum{ Gotoandstop (frame) }

oldNum=newNum

Boat5
  • 91
  • 1
  • 2