ActionScript 3.0 Design Patterns

(Chris Devlin) #1

388 | Chapter 10: State Pattern


TheAppendStateshown in Example 10-25 is the other new class. It’s virtually identi-


cal to theRecordStateclass in its makeup. However, because the processes of record-


ing and appending are very similar, this should come as no surprise. Save this class in


the same folder as the others for this application with the caption as the filename.


Example 10-24. RecordState.as


1 package
2 {
3 //Record State #5
4 import flash.net.NetStream;
5
6 class RecordState implements State
7 {
8 var videoWorks:VideoWorks;
9 public function RecordState(videoWorks:VideoWorks)
10 {
11 trace("--Record State--");
12 this.videoWorks=videoWorks;
13 }
14 public function startPlay(ns:NetStream,flv:String):void
15 {
16 trace("You have to stop first.");
17 }
18 public function stopAll(ns:NetStream):void
19 {
20 ns.close( );
21 trace("Stop recording.");
22 videoWorks.setState(videoWorks.getStopState( ));
23 }
24 public function startRecord(ns:NetStream,flv:String):void
25 {
26 trace("You're already recording");
27 }
28 public function startAppend(ns:NetStream,flv:String):void
29 {
30 trace("You have to stop first.");
31 }
32 public function doPause(ns:NetStream):void
33 {
34 trace("Must be playing to pause.");
35 }
36 }
37 }

Example 10-25. AppendState.as


1 package
2 {
3 //Append State #6
4 import flash.net.NetStream;
5
6
7 class AppendState implements State
Free download pdf