Game Development Reference
In-Depth Information
Flash is many lines of imports and code. Only having to type these
lines once by containing them within a flexible wrapper is the
essence of sound programming. Another reason to use a custom
class is to be able to trigger custom notifications for events.
Video playback in Flash generates a lot of events, some purely
informational and some error-based, and having to filter through
all the messages can be cumbersome when all you
re trying to do
is play a cutscene. By having the class listen for just the pertinent
messages and distill them down into a couple of useful events
simplifies the process even further.
This class isn
t as involved as the SoundEngine we looked at
earlier, and it is self-contained in one file.
package {
import flash.display.Sprite;
import flash.ui.Keyboard;
public class CutsceneManager extends Sprite{
The CutsceneManager extends the Sprite class, so it can easily be
added to the Stage like any other DisplayObject. Because it uses
video, it needs not only the Video class but also the NetConnection
and NetStream classes. Some examples I
ve seen import the entire
events package (import*), but for this example I
added each of the necessary events manually. Finally, we
ll include
the KeyboardEvent and Keyboard classes so that we can bind a key
to skip the video
a handy feature that prevents players from having
to potentially sit through a video over and over again.
public var skipKey:uint = Keyboard.SPACE;
protected var _nc:NetConnection;
protected var _stream:NetStream;
protected var _video:Video;
protected var _activeVideo:String;
We only need to keep track of a few variables for this class. The
skipKey property is exposed publicly, so you can set it to whatever
Search Nedrilad ::

Custom Search