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-18. VideoWorks.as (continued)<br />

}<br />

}<br />

this.state=state;<br />

}<br />

public function getState( ):State<br />

{<br />

return state;<br />

}<br />

public function getPlayState( ):State<br />

{<br />

return this.playState;<br />

}<br />

public function getStopState( ):State<br />

{<br />

return this.stopState;<br />

}<br />

public function getPauseState( ):State<br />

{<br />

return this.pauseState;<br />

}<br />

To test the additional pause class, all you need to do in the test class is add another<br />

button instance. With three buttons, a little more positioning thought has to go into<br />

it, but expanding the State design pattern is very easy. All the changes for adding the<br />

additional button are on lines 45-48 and 53. So just edit the TestVid.as file as shown<br />

in Example 10-19, and save it as TestPause.as.<br />

Example 10-19. TestPause.as<br />

1 package<br />

2 {<br />

3 //Implement FMS2 App and Test State Machine #6<br />

4 import flash.display.Sprite;<br />

5 import flash.net.NetConnection;<br />

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

7 import flash.media.Video;<br />

8 import flash.text.TextField;<br />

9 import flash.text.TextFieldType;<br />

10 import flash.events.MouseEvent;<br />

11 import flash.events.NetStatusEvent;<br />

12<br />

13 public class TestPause extends Sprite<br />

14 {<br />

15 private var nc:NetConnection=new NetConnection( );<br />

16 private var ns:NetStream;<br />

17 private var vid:Video=new Video(320,240);<br />

18 private var vidTest:VideoWorks;<br />

19 private var playBtn:NetBtn;<br />

20 private var stopBtn:NetBtn;<br />

21 private var flv:String;<br />

Expanding the State <strong>Design</strong>: Adding States | 379

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

Saved successfully!

Ooh no, something went wrong!