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-21. StopState.as<br />

1 package<br />

2 {<br />

3 //Stop State #2<br />

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

5<br />

6 class StopState implements State<br />

7 {<br />

8 var videoWorks:VideoWorks;<br />

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

10 {<br />

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

12 this.videoWorks=videoWorks;<br />

13 }<br />

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

15 {<br />

16 //Note: the second paramater - 0 - specifies an FLV file<br />

17 //the NetStream method is from Client-Side<br />

18 //<strong>ActionScript</strong> but works with AS <strong>3.0</strong><br />

19 //because ObjectEncoding is imported.<br />

20 ns.play(flv,0);<br />

21 trace("Begin playing");<br />

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

23 }<br />

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

25 {<br />

26 ns.publish(flv,"record");<br />

27 trace("Begin recording");<br />

28 videoWorks.setState(videoWorks.getRecordState( ));<br />

29 }<br />

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

31 {<br />

32 ns.publish(flv,"append");<br />

33 trace("Begin appending");<br />

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

35 }<br />

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

37 {<br />

38 trace("You're already stopped");<br />

39 }<br />

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

41 {<br />

42 trace("Must be playing to pause.");<br />

43 }<br />

44 }<br />

45 }<br />

46<br />

It may seem ironic that the state with the most active implementations of the video is<br />

called “stop.” However, only from the StopState should transitions be made to<br />

Append and Record states. The PlayState shown in Example 10-22 can be transitioned<br />

to from both the Stop state and the Pause state.<br />

Adding More States and Streaming Capabilities | 385

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

Saved successfully!

Ooh no, something went wrong!