Skip to main content
Known Participant
February 26, 2011
Answered

Sound -> 'complete' event vs. SoundChannel -> 'soundComplete' event

  • February 26, 2011
  • 3 replies
  • 2651 views

Hi,

Can anybody here explain practical difference between:

complete event of of Sound class and soundComplete event of SoundChannel class ?

What are exact differences between the two? When precisely are both events dispatched? Are they dispatched always together or not - which one is first?

Documentation is very laconic in this case (as usual mostly...).

Thanks ahead !

This topic has been closed for replies.
Correct answer somascope

Sound class

This doesn't actually have a complete event (in the way you might be thinking of). What you might be refering to (in the AS Docs) is usage of the flash.events.Event.COMPLETE event. This is only used for loading sound files, and tells you when the data has successfully loaded. So, typically, you'd just use the Sound class to manage the loading of things...

SoundChannel class: flash.events.Event.SOUND_COMPLETE

This is what should be used for detecting the completion of audio. The SoundChannel class is what you'd want to use to control the stopping/pausing/playing of things.

private var _s:Sound;

private var _sc:SoundChannel;

When loading audio...

_s = new Sound();

_sc = new SoundChannel();

_s.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

_s.load(new URLRequest(url));

When playing audio...

_sc = _s.play();

_sc.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);

3 replies

kglad
Community Expert
Community Expert
February 26, 2011

this may be a technicality that you don't understand but the answer you marked as correct is not correct.  the sound class does have a complete event.

ZiggizagAuthor
Known Participant
February 26, 2011

Sure,

I think it was miswording - Sound class has 'compete' event but it's about loading not playing. That means loading sound data may complete prior completing sund playing...

The problem is... It seems SoundChannel's SoundComplete event does not work for me... I need to clarify why... The sound finish to play and nothing happens!

ZiggizagAuthor
Known Participant
February 26, 2011

Yeap - this is because sound.play() method creates a new SoundChannel object each time it's called. One needs to attach event listener to this instance each time too.

somascope
somascopeCorrect answer
Inspiring
February 26, 2011

Sound class

This doesn't actually have a complete event (in the way you might be thinking of). What you might be refering to (in the AS Docs) is usage of the flash.events.Event.COMPLETE event. This is only used for loading sound files, and tells you when the data has successfully loaded. So, typically, you'd just use the Sound class to manage the loading of things...

SoundChannel class: flash.events.Event.SOUND_COMPLETE

This is what should be used for detecting the completion of audio. The SoundChannel class is what you'd want to use to control the stopping/pausing/playing of things.

private var _s:Sound;

private var _sc:SoundChannel;

When loading audio...

_s = new Sound();

_sc = new SoundChannel();

_s.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

_s.load(new URLRequest(url));

When playing audio...

_sc = _s.play();

_sc.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);

ZiggizagAuthor
Known Participant
February 26, 2011

Thank you guys !


kglad
Community Expert
Community Expert
February 26, 2011

the sound class complete event is dispatched if you load a sound (eg, mp3 file) into a sound instance and that load completes.

the soundchannel's soundcomplete event is dispatched if you play a sound and that sound completes its play.