Skip to content

Commit

Permalink
Sound3D now dispatches Event.SOUND_COMPLETE. Closes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
richardolsson committed Jun 19, 2012
1 parent ef96409 commit f257968
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/away3d/audio/Sound3D.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ package away3d.audio
{
import away3d.audio.drivers.*;
import away3d.containers.ObjectContainer3D;


import flash.events.Event;
import flash.geom.*;
import flash.media.*;

/**
* Dispatched when end of sound stream is reached (bubbled from the internal sound object).
*/
[Event(name="soundComplete", type="flash.events.Event")]

/**
* <p>A sound source/emitter object that can be positioned in 3D space, and from which all audio
Expand Down Expand Up @@ -50,6 +56,7 @@ package away3d.audio
_driver.sourceSound = _sound;
_driver.volume = volume;
_driver.scale = scale;
_driver.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);

_refv = new Vector3D;
_inv_ref_mtx = new Matrix3D;
Expand Down Expand Up @@ -215,5 +222,11 @@ package away3d.audio
_driver.updateReferenceVector(_refv);
}
*/


private function onSoundComplete(ev : Event) : void
{
dispatchEvent(ev.clone());
}
}
}
3 changes: 2 additions & 1 deletion src/away3d/audio/drivers/AbstractSound3DDriver.as
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package away3d.audio.drivers
{
import flash.events.EventDispatcher;
import flash.geom.*;
import flash.media.*;

public class AbstractSound3DDriver
public class AbstractSound3DDriver extends EventDispatcher
{
protected var _ref_v:Vector3D;
protected var _src:Sound;
Expand Down
3 changes: 2 additions & 1 deletion src/away3d/audio/drivers/ISound3DDriver.as
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package away3d.audio.drivers
{
import flash.events.IEventDispatcher;
import flash.geom.*;
import flash.media.*;

public interface ISound3DDriver
public interface ISound3DDriver extends IEventDispatcher
{
/**
* The sound object (flash.media.Sound) to play at the point of the sound
Expand Down
11 changes: 10 additions & 1 deletion src/away3d/audio/drivers/SimplePanVolumeDriver.as
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package away3d.audio.drivers
{
import away3d.audio.SoundTransform3D;


import flash.events.Event;
import flash.geom.*;
import flash.media.*;

Expand Down Expand Up @@ -43,6 +44,7 @@ package away3d.audio.drivers
// start from beginning of file.
pos = _paused? _pause_position : 0;
_sound_chan = _src.play(pos, 0, _st3D.soundTransform);
_sound_chan.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
}


Expand All @@ -51,12 +53,14 @@ package away3d.audio.drivers
_paused = true;
_pause_position = _sound_chan.position;
_sound_chan.stop();
_sound_chan.removeEventListener(Event.SOUND_COMPLETE, onSoundComplete);
}


public function stop() : void
{
_sound_chan.stop();
_sound_chan.removeEventListener(Event.SOUND_COMPLETE, onSoundComplete);
}


Expand Down Expand Up @@ -98,5 +102,10 @@ package away3d.audio.drivers
_sound_chan.soundTransform = _st3D.soundTransform;
}


private function onSoundComplete(ev : Event) : void
{
this.dispatchEvent(ev.clone());
}
}
}

0 comments on commit f257968

Please sign in to comment.