Hi guys, it seems there are a lot of problems with sound control with flash, and i (now seeming studpidlY) decided to undertake a project where i can have multiple sounds at once, and turn them off (individually) at the click of a button.
Please see the code
function soundSelected(evt:MouseEvent):void
{
// Pushes the filename into a playlist array.;
playlistArray.push(evt.target.fileName);
// I NEED TO STOP THIS SOUND FROM BEING ABLE TO PLAY AGAIN!
evt.target.enabled = false;
for (var i:int = 0; i < playlistArray.length; i++)
{
var channel = new SoundChannel();// Creates new sound Channel for each element
var snd = new Sound();// Creates new snd variable for each element
var soundTrans:SoundTransform = new SoundTransform(.2,0);// New ST
snd.load(new URLRequest(evt.target.fileName));// Loads fileName of target;
channel = snd.play(0,9);// Plays and set loop
}
// Adding small icons to the playlist bar.
var iconToAdd = iconsArray[evt.target.iconNo] as MovieClip;
sprite1.addChild(iconToAdd); // Adds the child.
bassX = sprite1.width + margin; // Sets the small icons position
iconToAdd.x = bassX; // Sets the small icons position
iconToAdd.y = -20; // Sets the small icons position
iconsOnArray.push(iconToAdd); // Pushes the icons on the playlist to an array for reference.
// Adds event listener to each of the icons that gets added to the playlist.
iconsOnArray[evt.target.iconNo].addEventListener(MouseEvent.CLICK, removeIcon);
}
// A Function to remove the small icon
function removeIcon(m:MouseEvent){
var iconToRemove = m.target as MovieClip; // set the m.target as a movieclip
sprite1.removeChild(iconToRemove); // remove it from the screen
trace (m.target.clip); // This displays the mp3 file i wish to stop
channel.stop(); // HOW DO I REMOVE THIS??
}
Obviously there is more code but these are the two functions that deal with the playing of sounds, the adding of icons (that form a playlist of clips that are being played) and also to remove these icons.
Basically when i click a button, it play a song (depending on the .target.FileName which is declared elsewhere), it then adds a small icon to a navigation bar so the user can see easily which sounds are on (this is depending on the .target.IconNo which again is declared elsewhere). I then add an event listener to the small icon that is on the stage, that calls the removeIcon function.
At the moment it adds the small icon, then when i click the small icon, it removes it from the screen, how can i link it so that it stops playing the sound it refers too? any ideas please, im loosing more and more hair, sleep and other things.
As always, thanks for looking. If you are confused i can upload the .swf so yous ee what i mean.