Game Development Reference
In-Depth Information
When you test your SWF, you should hear the sound effect play.
Note that we create a reference to the SoundEngine for conveni-
ence.Ifyouweremerelycallingasinglesoundeffectinascript
and had no reason to store a reference, you could shorten the call
this way:
SoundEngine.getInstance().playSound( " Explosion " );
Becausethisengineonlyexposestheexistingfunctionalityof
the Sound classes in a simpler and more convenient way, there is
plenty of other functionality that could be added in companion
classes. For instance, the ability to fade out sounds over time or
crossfade sounds to create musical transitions are both features
that don
t make sense in a basic sound engine but are very useful
in games. In fact, we
'
ll now look at a companion class, which a
coworker of mine created based on the SoundEngine. Many thanks
to Curry McKnight for this code! It makes use of TweenLite, just as
the example in Chapter 7.
'
public class SoundTweener
{
public static function allFrom( _duration:Number, _vars:
Object ):TweenGroup
{
var soundList:Object = SoundEngine.getInstance().
soundList;
var soundArray:Array = new Array();
for each( var soundObj:SoundEngineObject in soundList)
soundArray.push( soundObj );
if( soundArray.length )
{
return TweenGroup.allFrom( soundArray,
_duration, _vars, TweenLite );
}
else
{
return null;
}
}
public static function allTo( _duration:Number, _vars:
Object ):TweenGroup
{
var soundList:Object = SoundEngine.getInstance().
soundList;
var soundArray:Array = new Array();
for each(var soundObj:SoundEngineObject in soundList)
soundArray.push( soundObj );
Search Nedrilad ::




Custom Search