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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 10-22. PlayState.as<br />

1 package<br />

2 {<br />

3 //Play State #3<br />

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

5<br />

6 class PlayState implements State<br />

7 {<br />

8 var videoWorks:VideoWorks;<br />

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

10 {<br />

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

12 this.videoWorks=videoWorks;<br />

13 }<br />

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

15 {<br />

16 trace("You're already playing");<br />

17 }<br />

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

19 {<br />

20 ns.close( );<br />

21 trace("Stop playing.");<br />

22 videoWorks.setState(videoWorks.getStopState( ));<br />

23 }<br />

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

25 {<br />

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

27 }<br />

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

29 {<br />

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

31 }<br />

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

33 {<br />

34 ns.togglePause( );<br />

35 trace("Start pausing.");<br />

36 videoWorks.setState(videoWorks.getPauseState( ));<br />

37 }<br />

38 }<br />

39 }<br />

40<br />

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

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

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

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

transitions are to the Stop and Pause states. The Pause state is shown in<br />

Example 10-23.<br />

386 | Chapter 10: State Pattern

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

Saved successfully!

Ooh no, something went wrong!