ActionScript 3.0 Design Patterns

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

Other than adding instances of the new states, nothing is too different from the pre-


vious versions in theVideoWorksclass shown in Example 10-26. This is a case where


little change shows the strength of the State design structure. Not only has the appli-


cation been expanded to include two additional classes for record and append, it’s


also changed from a simple Flash Player using progressive download to play a video


to a Flash Media Server 2 streaming media application.


8 {

9 var videoWorks:VideoWorks;
10 public function AppendState(videoWorks:VideoWorks)
11 {
12 trace("--Append State--");
13 this.videoWorks=videoWorks;
14 }
15 public function startPlay(ns:NetStream,flv:String):void
16 {
17 trace("You have to stop first.");
18 }
19 public function stopAll(ns:NetStream):void
20 {
21 ns.close( );
22 trace("Stop appending.");
23 videoWorks.setState(videoWorks.getStopState( ));
24 }
25 public function startRecord(ns:NetStream,flv:String):void
26 {
27 trace("You have to stop first.");
28 }
29 public function startAppend(ns:NetStream,flv:String):void
30 {
31 trace("You're already appending");
32 }
33 public function doPause(ns:NetStream):void
34 {
35 trace("Must be playing to pause.");
36 }
37 }
38 }

Example 10-26. VideoWorks.as


1 package
2 {
3 //Context Class #7
4 import flash.net.NetStream;
5 public class VideoWorks
6 {
7 var playState:State;
8 var stopState:State;
9 var recordState:State;
10 var appendState:State;

Example 10-25. AppendState.as (continued)

Free download pdf