ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Adding More States and Streaming Capabilities | 387

Like the Play state, little is changed with the Pause state shown in Example 10-23,


because it only toggles between playing and not playing, and can’t pause a recording.


TheRecordStateclass is a whole new state. If you look closely, it’s very close to the


PlayStateclass, with the exception that it can’t transition to the Pause state. Remem-


ber that while in the Record state, the only option is to stop recording, and that is


how the stopAll( ) method is implemented in the RecordState class in


Example 10-24. Save the new state with the caption name as the filename. Be sure to


save it in the same folder as the other files.


Example 10-23. PauseState.as


1 package
2 {
3 //Pause State #4
4 import flash.net.NetStream;
5
6 class PauseState implements State
7 {
8 var videoWorks:VideoWorks;
9 public function PauseState(videoWorks:VideoWorks)
10 {
11 trace("--Pause State--");
12 this.videoWorks=videoWorks;
13 }
14 public function startPlay(ns:NetStream,flv:String):void
15 {
16 trace("You have to go to unpause");
17 }
18 public function stopAll(ns:NetStream):void
19 {
20 trace("Don't go to Stop from Pause");
21 }
22 public function startRecord(ns:NetStream,flv:String):void
23 {
24 trace("You have to stop first.");
25 }
26 public function startAppend(ns:NetStream,flv:String):void
27 {
28 trace("You have to stop first.");
29 }
30 public function doPause(ns:NetStream):void
31 {
32 ns.togglePause( );
33 trace("Quit pausing.");
34 videoWorks.setState(videoWorks.getPlayState( ));
35 }
36 }
37
38 }
Free download pdf