Copy link to clipboard
Copied
Hi,
I have the following code:
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.Event;
import flash.events.MouseEvent;
var ruta:URLRequest=new URLRequest("afternoonnaps.wav");
var sonido:Sound = new Sound();
var canal:SoundChannel = new SoundChannel();
sonido.load(ruta);
sonido.addEventListener(Event.COMPLETE, carga);
function carga(event:Event):void {
detener_btn.addEventListener(MouseEvent.CLICK, detener);
}
function detener(event:MouseEvent):void {
canal.stop();
}
I want to stop a sound with a button and this is the error that I get:
Error #2044: IOErrorEvent Unhandled: text=Error #2032: Sequence or Stream error.
at web17_fla::MainTimeline/frame10()
Please, Can you help me?.
1 Correct answer
no sound has been started so you can't apply a stop() to that soundchannel.
Copy link to clipboard
Copied
no sound has been started so you can't apply a stop() to that soundchannel.
Copy link to clipboard
Copied
Hi,
thanks for your reply.
How can I do to start a sound?.
Please, Could you add the whole code in AS3?.
Thank you very much.
Copy link to clipboard
Copied
:
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.Event;
import flash.events.MouseEvent;
var ruta:URLRequest=new URLRequest("afternoonnaps.wav");
var sonido:Sound = new Sound();
var canal:SoundChannel;
sonido.load(ruta);
sonido.addEventListener(Event.COMPLETE, carga);
function carga(event:Event):void {
canal = sonido.play();
detener_btn.addEventListener(MouseEvent.CLICK, detener);
}
function detener(event:MouseEvent):void {
canal.stop();
}
Copy link to clipboard
Copied
Thanks!.
Where I must put the sound?. I have it in the library in a folder called "sons".
Copy link to clipboard
Copied
if it's in your library you wouldn't load it. assign it a class (eg, Sons) and use:
var sonido:Sons = new Sons();
var canal:SoundChannel;
canal = sonido.play();
detener_btn.addEventListener(MouseEvent.CLICK, detener);
function detener(event:MouseEvent):void {
canal.stop();
}
Copy link to clipboard
Copied
Please, Can you add the code again with the sound location?.
Copy link to clipboard
Copied
what?
Copy link to clipboard
Copied
I go to properties in the sound> export action script > class:AfternoonNaps> bass class: flash.media.Sound. Is that right?.
Copy link to clipboard
Copied
I did it!, the error was that I have a layer with the sound and it couldn´t stop it.
Many thanks for your patience and the help.
Copy link to clipboard
Copied
Kglad, How I must do to play a loop with the sound?.
Copy link to clipboard
Copied
the 2nd parameter in the play method is a loops parameter:
var canal:SoundChannel=sonido.play(0,99); // plays sound from 0 seconds, 99 loops
Copy link to clipboard
Copied
Thank you mate!!!.
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
you're welcome.