-1

I Am beginner with Flash and ActionScript 3 I have 8 lip code for a character that i did create in different frames, so i want to play my animation frame by frame but with a different order to form a phrase that my character will say I did try it on my own but i did not successed:

    stop();

var tableau = new Array(); 
tableau[0]=2;
tableau[1]=4;
tableau[2]=1;
tableau[3]=7;
tableau[4]=8;
tableau[5]=1;
tableau[6]=7;

for(var i =0;i<tableau.length;i++){
    trace(tableau[i]==this.currentFrame);
    if(tableau[i]==this.currentFrame){
        gotoAndPlay(tableau[i]);
        trace(this.currentFrame);
    }
}
IT World
  • 165
  • 1
  • 10
  • If you use "for" you'll end up with the last frame before the frames drawn, because the whole for block will be executed less than a 10ms, think that how long your animation suppose to be (i believe it's not 10ms) , use timer or [enter_frame](https://stackoverflow.com/questions/9264681/as3-how-much-time-until-next-frame-screen-draw) to change frames, this will help you to see all sequence in animation – Ömer Erden Dec 18 '18 at 13:41

1 Answers1

2

It's pretty much simple. What you need is to subscribe to the special event that fires once per frame and move the playhead once per frame according to the plan.

stop();

var Frames:Array;

// This will prevent things from overlapping
// if one of the frames on the list is the
// current one and playhead will hit here
// once again (and try to execute code).
if (Frames == null)
{
    Frames = [2,4,1,7,8,1,7];
    addEventListener(Event.ENTER_FRAME, onFrame);
}

function onFrame(e:Event):void
{
    // Get the next frame index and remove it from the list.
    var aFrame:int = Frames.shift();

    // If there are no more frames to show,
    // unsubscribe from the event.
    if (Frames.length < 1)
    {
        removeEventListener(Event.ENTER_FRAME, onFrame);
    }

    gotoAndStop(aFrame);
}
Organis
  • 7,243
  • 2
  • 12
  • 14
  • Thank you so much for your help Do you know how can i synchronize it with the audio file ? – IT World Dec 18 '18 at 13:58
  • 1
    @ITWorld What do you mean by "synchronize"? Please explain in more details. – Organis Dec 18 '18 at 15:16
  • I want when i run my code, my character will talk, for example he will say Hello, so how can i make my character talk at the same time when my audio file is played, phoneme by phoneme?? – IT World Dec 18 '18 at 15:34
  • 1
    @ITWorld I'm still not sure I understand what you want to do, however, this might be what you are looking for. The **Sound** class dispatches **SampleDataEvent.SAMPLE_DATA** event which contains raw data for the sound that is about to be played. You can extract these data (Google > **as3 read sound data** for example or official documentation: https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/SampleDataEvent.html) and learn how to read them for peaks. – Organis Dec 18 '18 at 16:19
  • What i want to do is lip sync with the audio that is played – IT World Dec 19 '18 at 08:26
  • 1
    @ITWorld Then I was right and you need to process the audio data to do so. Probably you need to watch for volume peaks and determine vowels being spoken. I'm not a speech recognition pro and I never actually coded the audio analysis, so I cannot help you any further. – Organis Dec 19 '18 at 09:41
  • but i really thank you for your help and your time wish you best of luck and have a good day – IT World Dec 19 '18 at 09:49