Game Development Reference
In-Depth Information
video stream, messages are broadcast and captured by one event.
Usingaswitchstatement,wefilterthroughthemforthemessages
importanttous.Inthiscase,wewanttoknowwhetherthevideo
fails to load, when the video actually starts playing, and when it
finishes. There are two other events that we need to set up listeners
for, which are error-based. It
s not that we should be overly
concerned with these errors, but without a listener attached to them,
they will throw real run-time errors that can break other parts of your
code. Now that we
'
'
ve covered all the
under-the-hood
code, we
'
ll
take a look at the main methods used to control the manager.
public function playCutscene(url:String) : void {
_activeVideo = url;
_stream = new NetStream(_nc);
_stream.addEventListener(NetStatusEvent.NET_STATUS,
netStatus, false, 0, true);
_stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,
asyncError, false, 0, true);
_video.attachNetStream(_stream);
_stream.play(url);
if (stage) stage.addEventListener(KeyboardEvent.KEY_
DOWN, skipCutscene, false, 0, true);
}
public function stopCutscene(eventType:String = Event.CANCEL) :
void {
_stream.close();
_video.clear();
dispatchEvent(new Event(eventType));
if (stage) stage.removeEventListener(KeyboardEvent.KEY_
DOWN, skipCutscene);
}
public function get activeVideo():String {
return _activeVideo;
}
protected function skipCutscene(e:KeyboardEvent) {
if (e.keyCode == skipKey) stopCutscene();
}
The playCutscene method is the heart of this class. It accepts a
URL string, sets up the stream, and links it to the video. It also adds
a listener for keystrokes, so you can define a key that will skip the
cutscene. You probably noticed back in the netStatus method that
on the video finishing it calls stopCutscene and passes a parameter
of Event.COMPLETE. By default, the stopCutscene method will
Search Nedrilad ::




Custom Search