ActionScript 3.0 Design Patterns

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

It may seem ironic that the state with the most active implementations of the video is


called “stop.” However, only from theStopState should transitions be made to


Append and Record states. ThePlayStateshown in Example 10-22 can be transi-


tioned to from both the Stop state and the Pause state.


Example 10-21. StopState.as


1 package
2 {
3 //Stop State #2
4 import flash.net.NetStream;
5
6 class StopState implements State
7 {
8 var videoWorks:VideoWorks;
9 public function StopState(videoWorks:VideoWorks)
10 {
11 trace("--Stop State--");
12 this.videoWorks=videoWorks;
13 }
14 public function startPlay(ns:NetStream,flv:String):void
15 {
16 //Note: the second paramater - 0 - specifies an FLV file
17 //the NetStream method is from Client-Side
18 //ActionScript but works with AS 3.0
19 //because ObjectEncoding is imported.
20 ns.play(flv,0);
21 trace("Begin playing");
22 videoWorks.setState(videoWorks.getPlayState( ));
23 }
24 public function startRecord(ns:NetStream,flv:String):void
25 {
26 ns.publish(flv,"record");
27 trace("Begin recording");
28 videoWorks.setState(videoWorks.getRecordState( ));
29 }
30 public function startAppend(ns:NetStream,flv:String):void
31 {
32 ns.publish(flv,"append");
33 trace("Begin appending");
34 videoWorks.setState(videoWorks.getAppendState( ));
35 }
36 public function stopAll(ns:NetStream):void
37 {
38 trace("You're already stopped");
39 }
40 public function doPause(ns:NetStream):void
41 {
42 trace("Must be playing to pause.");
43 }
44 }
45 }
46
Free download pdf