0
votes

I currently have a difficulty removing specific sounds from playing when I advance through the timeline on a particular project.

The user chooses a particular item on the timeline which will display a specific movieclip and will then play a specific sound on MOUSE_DOWN.

The eventListener for MOUSE_DOWN which exists as follows:

stage.addEventListener(MouseEvent.MOUSE_DOWN, sprayWater);
stage.addEventListener(MouseEvent.MOUSE_UP, stopWater);

function sprayWater(event:MouseEvent):void
{
    waterarm.gotoAndStop(2);
    trace("SPRAYING WATER");    
}

function stopWater(event:MouseEvent):void
{
    waterarm.water.gotoAndPlay("waterE");   
}

on frame 2 of 'waterarm' is a movieclip called 'water' that contains an animation of water and the following code to start the water sound:

var sfxWater:sfxwater;
var waterChannel:SoundChannel;
sfxWater = new sfxwater;
waterChannel = sfxWater.play();

on the frame "waterE" an animation of the water disappearing exists and the code sfxWater.stop();.

When the user progresses beyond this frame on the root timeline, the sound effect of water still remains on MOUSE_DOWN despite the movieclip no longer existing on the timeline at that point.

The ideal outcome will be the individual sound playing on MOUSE_DOWN and stopping on MOUSE_UP only when this movieclip is visible on the main timeline. If anybody can provide any assistance in being able to prevent the sound from playing and removing this event listener (through code on the main timeline if possible) it would be greatly appreciated.

Regards, Darren

1
Is there something wrong with: function stopWater(event:MouseEvent):void { removeEventListener(MouseEvent.MOUSE_DOWN, sprayWater); removeEventListener(MouseEvent.MOUSE_UP, stopWater); waterarm.water.gotoAndPlay("waterE"); }IAmMearl
thanks for your reply Michael. I didn't state in my original post that the user doesn't move from this frame when they 'spray water', they should be able to press the button as many times as they like, there is collision detection on the root timeline which determines whether they progress elsewhere or stay on this frame when MOUSE_DOWN.Darren Singleton
"flash gives me an array basically saying that 'sprayWater' doesn't exist." is that the function or a movieclip? You might want to look into a custom dispatchEvent class or add a line in your mouse_down that says something like: if(movieclip){//if the movieclip exists //do stuff } I need to get used to the enterkey submitting comments...IAmMearl
sorry, that was a typo - array was meant to be error. sprayWater is the function, but it still triggers when I hold the mouse button down . . .Darren Singleton

1 Answers

1
votes

If stopping the sound is all that you want why not use SoundMixer.stopAll().

You can use it in the MOUSE_UP event after checking if the said movieclip's visible property.