# Sound player : music is not played when loaded

**URL:** https://forum.kirupa.com/t/sound-player-music-is-not-played-when-loaded/317560
**Category:** flash
**Created:** [December 24, 2010, 2:00pm UTC](https://forum.kirupa.com/t/sound-player-music-is-not-played-when-loaded/317560 "2010-12-24T14:00:11Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Paposs122](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@Paposs122](https://forum.kirupa.com/u/Paposs122)
#### Post date: [December 24, 2010, 2:00pm UTC](https://forum.kirupa.com/t/sound-player-music-is-not-played-when-loaded/317560/1 "2010-12-24T14:00:11Z")

</div>

Hello everybody!

I have or more precisely I had a problem, I was looking for a flash audio player that doesn’t play the music directly when it is loaded but only with buttons, so firstly the music is loaded with an URL then I can play it if I want with buttons.  
I tried to change some scripts of kirupa’s site, but it was always a failure,  
for example I tried to change this sound loader [http://www.kirupa.com/developer/as3/playing\_sounds.htm](http://www.kirupa.com/forum/../developer/as3/playing_sounds.htm)

The Action script (3.0):

> var soundClip:Sound; function init() { soundClip = new Sound(); soundClip.load(new URLRequest(“\<path to sound file\>”)); soundClip.addEventListener(Event.COMPLETE, soundLoaded); soundClip.addEventListener(ProgressEvent.PROGRESS, soundLoading);} init(); function soundLoaded(e:Event) { soundClip.play();} function soundLoading(e:[COLOR=#0000D0]ProgressEvent[/COLOR]) { // preloader information goes here}

I tried to change the soundClip.play by a gotoAndPlay(2), and in frame 2  
I put a play button occured “play\_btn” whith the code

> play\_btn.onRelease = function () {

soundClip.play();

}

but there was an error message

Firstly :  
1119: talking about the property onRelease maybe undefined, via the reference static flash.display:Simplebutton

Secondly:  
Warning: 1090: Problem of migration, about ActionScript 3.0, and explaining something about putting something like addEventListener(‘click’,callback\_handler)

Finnally I found a rather simple code that works:

> 

//1.  
var my\_sound:Sound = new Sound();  
my\_sound.load(new URLRequest(“5.mp3”));  
var my\_channel:SoundChannel = new SoundChannel();

//2.  
play\_btn.addEventListener(MouseEvent.CLICK, playSound);  
stop\_btn.addEventListener(MouseEvent.CLICK, stopSound);

//3.  
function playSound(event:MouseEvent):void{  
my\_channel = my\_sound.play();  
}

//4.  
function stopSound(event:MouseEvent):void{  
my\_channel.stop();  
}

But now, even it’s ok as it works,  
I WOULD LIKE TO UNDERSTAND WHAT I DID SO HERE ARE TWO QUESTIONS:

1.Can somebody explain me the error message please, I don’t understand well the idea of event listener :hangover: and to me it’s not really developped a lot in the tutorials even if I found some things.

2.What about the channel? I don’t understand, because there are several flash sound players scripts on the web but they don’t all use it, so when is it necessary, and when it isn’t?:h:

I am really sorry for my english and I hope you understand me if you don’t, do not hesitate to ask some details!🍺

Thanks for reading!! :batman:
