Skip to main content
Inspiring
August 9, 2013
Answered

Flash error in AS3. Use a button to stop a sound.

  • August 9, 2013
  • 2 replies
  • 1994 views

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?.

This topic has been closed for replies.
Correct answer kglad

no sound has been started so you can't apply a stop() to that soundchannel.

2 replies

kglad
Community Expert
August 9, 2013

:

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();

}

Inspiring
August 10, 2013

Thanks!.

Where I must put the sound?. I have it in the library in a folder called "sons".

kglad
Community Expert
August 10, 2013

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();

}

kglad
kgladCorrect answer
Community Expert
August 9, 2013

no sound has been started so you can't apply a stop() to that soundchannel.

Inspiring
August 9, 2013

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.