简体   繁体   English

Flash AS3 | 每个动画集的循环声音

[英]Flash AS3 | Looping sound for each animation set

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. 大学毕业后,我终于有时间回到练习Flash的工作上,我需要一些帮助来使声音循环播放并根据动画的播放部分进行更改。

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 | 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. 当涉及到基于音频/代码的任何东西时,我都很糟糕。

Well u can check about soundChannel. 好吧,您可以检查一下soundChannel。 soundChannel can stop() and play() ur audio. soundChannel可以停止()和播放()您的音频。 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 http://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html

also look this link for more info 也可以查看此链接以获取更多信息

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 当声音设置为“流”播放时,如果图形缓慢以使声音和动画保持同步,则Flash Player会定向声音并丢帧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM