10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 10-23. PauseState.as<br />

1 package<br />

2 {<br />

3 //Pause State #4<br />

4 import flash.net.NetStream;<br />

5<br />

6 class PauseState implements State<br />

7 {<br />

8 var videoWorks:VideoWorks;<br />

9 public function PauseState(videoWorks:VideoWorks)<br />

10 {<br />

11 trace("--Pause State--");<br />

12 this.videoWorks=videoWorks;<br />

13 }<br />

14 public function startPlay(ns:NetStream,flv:String):void<br />

15 {<br />

16 trace("You have to go to unpause");<br />

17 }<br />

18 public function stopAll(ns:NetStream):void<br />

19 {<br />

20 trace("Don't go to Stop from Pause");<br />

21 }<br />

22 public function startRecord(ns:NetStream,flv:String):void<br />

23 {<br />

24 trace("You have to stop first.");<br />

25 }<br />

26 public function startAppend(ns:NetStream,flv:String):void<br />

27 {<br />

28 trace("You have to stop first.");<br />

29 }<br />

30 public function doPause(ns:NetStream):void<br />

31 {<br />

32 ns.togglePause( );<br />

33 trace("Quit pausing.");<br />

34 videoWorks.setState(videoWorks.getPlayState( ));<br />

35 }<br />

36 }<br />

37<br />

38 }<br />

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

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

The RecordState class is a whole new state. If you look closely, it’s very close to the<br />

PlayState class, with the exception that it can’t transition to the Pause state. Remember<br />

that while in the Record state, the only option is to stop recording, and that is<br />

how the stopAll( ) method is implemented in the RecordState class in<br />

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

save it in the same folder as the other files.<br />

Adding More States and Streaming Capabilities | 387

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!