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-25. AppendState.as (continued)<br />

8 {<br />

9 var videoWorks:VideoWorks;<br />

10 public function AppendState(videoWorks:VideoWorks)<br />

11 {<br />

12 trace("--Append State--");<br />

13 this.videoWorks=videoWorks;<br />

14 }<br />

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

16 {<br />

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

18 }<br />

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

20 {<br />

21 ns.close( );<br />

22 trace("Stop appending.");<br />

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

24 }<br />

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

26 {<br />

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

28 }<br />

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

30 {<br />

31 trace("You're already appending");<br />

32 }<br />

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

34 {<br />

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

36 }<br />

37 }<br />

38 }<br />

Other than adding instances of the new states, nothing is too different from the previous<br />

versions in the VideoWorks class shown in Example 10-26. This is a case where<br />

little change shows the strength of the State design structure. Not only has the application<br />

been expanded to include two additional classes for record and append, it’s<br />

also changed from a simple Flash Player using progressive download to play a video<br />

to a Flash Media Server 2 streaming media application.<br />

Example 10-26. VideoWorks.as<br />

1 package<br />

2 {<br />

3 //Context Class #7<br />

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

5 public class VideoWorks<br />

6 {<br />

7 var playState:State;<br />

8 var stopState:State;<br />

9 var recordState:State;<br />

10 var appendState:State;<br />

Adding More States and Streaming Capabilities | 389

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

Saved successfully!

Ooh no, something went wrong!