Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Aug 09, 2013 Aug 09, 2013

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

TOPICS
ActionScript
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 09, 2013 Aug 09, 2013

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

Translate
Community Expert ,
Aug 09, 2013 Aug 09, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 09, 2013 Aug 09, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2013 Aug 09, 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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 09, 2013 Aug 09, 2013

Thanks!.

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2013 Aug 09, 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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 09, 2013 Aug 09, 2013

Please, Can you add the code again with the sound location?.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2013 Aug 09, 2013

what?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 09, 2013 Aug 09, 2013

I go to properties in the sound> export action script > class:AfternoonNaps> bass class: flash.media.Sound. Is that right?.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 09, 2013 Aug 09, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 11, 2013 Aug 11, 2013

Kglad, How I must do to play a loop with the sound?.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 11, 2013 Aug 11, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 11, 2013 Aug 11, 2013

Thank you mate!!!.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 11, 2013 Aug 11, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 09, 2013 Aug 09, 2013

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines