Packagecom.whirled.contrib
Classpublic class Jukebox

A Jukebox class for handling looping background music. This class assumes that each track is a level pack defined for a game, and that com.whirled.contrib.LevelPacks has been initalized with the level packs for this game so that it can call LevelPacks.getMediaURL(trackName) in start() to find out where to download the music from.



Protected Properties
 PropertyDefined by
  _currentChannel : SoundChannel
[static]
Jukebox
  _currentSong : Sound
[static]
Jukebox
  _eventMgr : EventHandlerManager
[static]
Jukebox
  _frameDispatcher : IEventDispatcher
[static]
Jukebox
  _loopCallback : Function = null
[static]
Jukebox
  _sounds : Map
[static]
Jukebox
  _volume : int = 30
[static]
Jukebox
Public Methods
 MethodDefined by
  
fadeIn():void
[static] Fade the current music in.
Jukebox
  
fadeOut():void
[static] Fade the current music out.
Jukebox
  
init(frameDispatcher:IEventDispatcher, eventMgr:EventHandlerManager = null):void
[static] init must be called before the Jukebox can handle crossfading and loading music correctly.
Jukebox
  
modifyVolume(by:int):int
[static] Modify the current volume level by the given amount.
Jukebox
  
setVolume(volume:int):void
[static] Set the volume level as a value between 0 and 100.
Jukebox
  
start(trackName:String, crossfade:Boolean = true, callback:Function = null):void
[static] Start a background audio track.
Jukebox
  
stop():void
[static] Stop playing the current music.
Jukebox
Protected Methods
 MethodDefined by
  
loop():void
[static]
Jukebox
  
soundComplete(event:Event):void
[static]
Jukebox
  
startSong(song:Sound, crossfade:Boolean):void
[static]
Jukebox
Public Constants
 ConstantDefined by
  DEFAULT_VOLUME : int = 30
[static]
Jukebox
  MAX_VOLUME : int = 100
[static]
Jukebox
Protected Constants
 ConstantDefined by
  FADE_TIME : int = 3000
[static]
Jukebox
Property detail
_currentChannelproperty
protected static var _currentChannel:SoundChannel
_currentSongproperty 
protected static var _currentSong:Sound
_eventMgrproperty 
protected static var _eventMgr:EventHandlerManager
_frameDispatcherproperty 
protected static var _frameDispatcher:IEventDispatcher
_loopCallbackproperty 
protected static var _loopCallback:Function = null
_soundsproperty 
protected static var _sounds:Map
_volumeproperty 
protected static var _volume:int = 30
Method detail
fadeIn()method
public static function fadeIn():void

Fade the current music in. Used in crossfading or for fading in music after calling fadeOut().

fadeOut()method 
public static function fadeOut():void

Fade the current music out.

init()method 
public static function init(frameDispatcher:IEventDispatcher, eventMgr:EventHandlerManager = null):void

init must be called before the Jukebox can handle crossfading and loading music correctly. The frameDispatcher must be a display object that will remain on the display list, as this class depends on constant ENTER_FRAME events to function properly. If an EventHandlerManager is provided, all event listeners will be registered using it. Otherwise, EventHandlers is used statically.

Parameters
frameDispatcher:IEventDispatcher
 
eventMgr:EventHandlerManager (default = null)
loop()method 
protected static function loop():void
modifyVolume()method 
public static function modifyVolume(by:int):int

Modify the current volume level by the given amount. This function will make sure the volume remains within the valid range of 0 to 100.

Parameters
by:int

Returns
int
setVolume()method 
public static function setVolume(volume:int):void

Set the volume level as a value between 0 and 100.

Parameters
volume:int
soundComplete()method 
protected static function soundComplete(event:Event):voidParameters
event:Event
start()method 
public static function start(trackName:String, crossfade:Boolean = true, callback:Function = null):void

Start a background audio track.

Parameters
trackName:String — the name of the level pack that contains the MP3 for this track.
 
crossfade:Boolean (default = true) — If true, this track will fade in, and any previous track will fade out. If false, this track will begin playing immediately.
 
callback:Function (default = null) — A zero-arg function that will be called each time a loop of the current song finishes and a new song is about to get played.
startSong()method 
protected static function startSong(song:Sound, crossfade:Boolean):voidParameters
song:Sound
 
crossfade:Boolean
stop()method 
public static function stop():void

Stop playing the current music.

Constant detail
DEFAULT_VOLUMEconstant
public static const DEFAULT_VOLUME:int = 30
FADE_TIMEconstant 
protected static const FADE_TIME:int = 3000
MAX_VOLUMEconstant 
public static const MAX_VOLUME:int = 100