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
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!!