开发者

Is there a way to use a sound channel on a movieclip?

开发者 https://www.devze.com 2023-02-21 02:23 出处:网络
The only way i can describe this is showing the code I have already then trying to explain what i want to do..

The only way i can describe this is showing the code I have already then trying to explain what i want to do.. Basically, I am creating a soundboard game, where at the bottom of the screen I will have a bar which is a movieclip, and I will be dragging other movieclips onto it and then clicking pay, and using an array and .push they will play in order. I am trying to put the sounds onto the movieclips using code. So far, I have this:

var snd1:Sound = newSound();
snd.load(newURLRequest("naturefrog.wav"));

var channel:SoundChannel;
snd.addEventListener

I am now stuck with what I would put for the listener to开发者_StackOverflow listen for.


See this answer for knowing when sounds have finished loading, if the sound is external: Loading a sound from an external source

Now once you're ready to play the sound and listen for when it completes, that's answered here: demonstrates setting up listeners for sound_complete, as well as looping


You should use the Flash API for Sound to determine what listeners to add. There are some helpful examples at the bottom of the page.

I assume you'll want to add:

snd.addEventListener(Event.COMPLETE, completeHandler);
snd.addEventListener(Event.ID3, id3Handler);
snd.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
snd.addEventListener(ProgressEvent.PROGRESS, progressHandler);


You are pushing the sound reference of a movieclip into an array when user drag it into a particular movieclilp, right? If you do so you can shift an element from array(array.shift, usually this removes and returns the first element of the array).

function playSoundInArray(){
    if(array.length){
        var snd:Sound = array.shift() as Sound;
        channel = snd.play();
        channel.addEventListener(Event.SOUND_COMPLETE, onSoundPlayed);
    }else{
        //Do something here if there is no sound reference or the array is empty
    }
}

function onSoundPlayed(e:EVent){
    channel.removeEventListener(Event.SOUND_COMPLETE, onSoundPlayed);
    playSoundInArray();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消