Game Development Reference
In-Depth Information
_name = name;
super(type, bubbles, cancelable);
}
override public function clone() : Event {
return new SoundEngineEvent(type, name, bubbles,
cancelable);
}
public function get name():String {
return _name;
}
}
}
The three constants defined at the top of the class are used to
clearly define the types of events that the SoundEngine can dis-
patch. The SoundEngineEvent is justlikeanormalevent,except
that it contains one extra piece of data: the name of the sound that
generated the event. Without this, there would be no distinguishing
of one sound event from the next, especially when many were
occurring all at once.
Using the Class
Now that we have the class complete, we
ll set up a test file to
ensure that it is working. Create a new ActionScript 3 FLA. Import
the test sound effect provided to the library. To set up the sound to
be available to ActionScript, double-click it to pull up its Properties
panel. Under the Linkage area, select the checkbox to export the
Sound for ActionScript. In the Class field, type
'
Explosion
;thisis
how you
ll refer to this sound from this point on. Flash will auto-
matically fill in the Base Class as an object of type Sound.
Save the FLA alongside the SoundEngine class file so Flash will
know how to find it. Open the Actions panel and type the following
in frame 1:
'
var se:SoundEngine = SoundEngine.getInstance();
se.playSound(
"
Explosion
"
);
Figure 8.5 Use the Linkage
properties to set up a sound
for export.
Search Nedrilad ::




Custom Search