Game Development Reference
In-Depth Information
this internal class, only the SoundEngine is capable of creating
itself. We will accomplish this with an additional line at the bottom
of the file:
class SoundEngineSingleton {}
re
done. Now anyone who uses the class has only one way of getting to
the SoundEngine and is prevented from accidentally breaking
some of its functionality or creating more than one engine. Think of
it as the key to the engine; without it the engine won
Flash infers that a class declared this way is internal, so we
'
'
t start.
ve defined the basic properties of the engine and
established a way to create and access it, we should jump over to
the SoundEngineObject class to define exactly what each object will
do, when created.
Now that we
'
static private var _canPlaySound:Boolean = Capabilities.hasAudio;
public var name:String;
public var sound:Sound;
public var channel:SoundChannel;
protected var _transform:SoundTransform;
protected var _playing:Boolean = false;
protected var _muted:Boolean = false;
protected var _paused:Boolean = false;
protected var _pauseTime:Number;
protected var _loops:uint;
protected var _offset:Number;
public function SoundEngineObject(name:String, sound:Sound) {
this.name = name;
this.sound = sound;
}
Thefirstpropertyisastaticflagcalled_canPlaySound,which
reads the system
s ability to play sound files. What we discovered
through testing was that on a machine with a broken or missing
sound card, any requests to play sound by Flash will cause a runtime
error. While Adobe should have just chosen to suppress any such
errors, we introduced this flag to do an initial check and make sure
that no sounds are played if such a scenario exists. Before performing
any sound-based operations, the class will check this value to make
sure no error will be caused. Each engine object stores the basic infor-
mation about the sound it creates, such as the channel, the transform,
the number of times it should loop, and so on. Additionally, each
object has a name property, which is how the engine will keep track
of, or index, them. Now, we
'
ll add some methods to the object, so
that it can perform actions and give information.
'
Search Nedrilad ::




Custom Search