0

with University done I've finally had time to go back to practicing my Flash work, and I need some help with getting sound to loop and change depending on what part of the animation is playing.

This is also partly a follow up question to an older one I asked, so look here to get more detail as to where I'm coming from if you don't understand! (I've solved that issue, the current one relates to following up on it!)

Flash AS3 | Finishing current animation set before code is executed

The situation is basic: I have two different scenes, one of a man walking and one of a man running. It loops seamlessly of the man walking until you hit a button, where it finishes the animation then starts looping the run animation. Likewise, hitting the button again, finishes the loop before going back to the looping walk animation. The code for the button is below.

  import flash.events.MouseEvent;


    Next2.addEventListener(MouseEvent.CLICK, Change_2);

function Change_2(event: MouseEvent): void

{
    addEventListener(Event.ENTER_FRAME, enterFrame);
    function enterFrame(e:Event):void {
    if (currentFrame == 30) {
        gotoAndPlay(31);
        removeEventListener(Event.ENTER_FRAME, enterFrame);
    }

}
}

My issue is trying to get a footstep sound to match up with these animations. So while the man is walking, the 'walking footsteps' sound clip will play and loop alongside the animation, and when the button is pushed and the animation moves into the running animation, the 'running footsteps'' sound will play.

Any help on this would be much appreciated. I'm terrible when it comes to anything audio/code based.

2 Answers 2

0

Well u can check about soundChannel. soundChannel can stop() and play() ur audio. So import ur external sound or use internal one. ur code probably seems like this.

var mySound:Sound = new Sound(new URLRequest("YourSoundPath"));
var sc:SoundChannel = new SoundChannel();

//when u wanna play
sc = mySound.play();
//when u wanna stop
sc = mySound.stop();

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html

also look this link for more info

0

If you want to really MATCH the footsteps to the animation (for example, the step sound should play when the player have put his feet down) the only sure way to do that is to place the sound on a different layer where your animation is and set the sound to play as "stream" (if i remember correctly).

Otherwise the animation might be out of sync because of different computer capabilities, current computer or graphics card load etc.

When the sound is set to play as "stream" the flash player is orienting on the sound and drop frames if the graphics are slow to keep the sound and animation in sync

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.