ActionScript 3.0 Design Patterns

(Chris Devlin) #1

386 | Chapter 10: State Pattern


The Play state is little changed from previous versions. While playing a video, the


structure won’t allow direct transitioning to either recording or appending a video. It


would be possible to do so, but you’d run the risk over overwriting a video you’re


watching with one you want to record. So, from the Play state, the only possible


transitions are to the Stop and Pause states. The Pause state is shown in


Example 10-23.


Example 10-22. PlayState.as


1 package
2 {
3 //Play State #3
4 import flash.net.NetStream;
5
6 class PlayState implements State
7 {
8 var videoWorks:VideoWorks;
9 public function PlayState(videoWorks:VideoWorks)
10 {
11 trace("--Play State--");
12 this.videoWorks=videoWorks;
13 }
14 public function startPlay(ns:NetStream,flv:String):void
15 {
16 trace("You're already playing");
17 }
18 public function stopAll(ns:NetStream):void
19 {
20 ns.close( );
21 trace("Stop playing.");
22 videoWorks.setState(videoWorks.getStopState( ));
23 }
24 public function startRecord(ns:NetStream,flv:String):void
25 {
26 trace("You have to stop first.");
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 ns.togglePause( );
35 trace("Start pausing.");
36 videoWorks.setState(videoWorks.getPauseState( ));
37 }
38 }
39 }
40
Free download pdf