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

package<br />

{<br />

//State Interface #1<br />

import flash.net.NetStream;<br />

interface State<br />

{<br />

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

function stopPlay(ns:NetStream):void;<br />

}<br />

}<br />

In the following StopState class shown in Example 10-8, you will note that the<br />

startPlay( ) method has been implemented to actually play the selected FLV file.<br />

That transition to the Play state is not to start playing the video, but rather to set the<br />

state where the video is playing.<br />

Example 10-8. StopState.as<br />

package<br />

{<br />

//Stop State #2<br />

import flash.net.NetStream;<br />

}<br />

class StopState implements State<br />

{<br />

private var videoWorks:VideoWorks;<br />

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

{<br />

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

this.videoWorks=videoWorks;<br />

}<br />

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

{<br />

ns.play(flv);<br />

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

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

}<br />

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

{<br />

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

}<br />

}<br />

Note that in the PlayState class shown in Example 10-9, the startPlay( ) method<br />

wisely does nothing other than issue a statement to remind the user that the video is<br />

already playing. In the test mode, the message appears in the Output window, but<br />

when the user’s working with it, no message is issued. The feedback issues from the<br />

playing video.<br />

368 | Chapter 10: State Pattern

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

Saved successfully!

Ooh no, something went wrong!