ActionScript 3.0 Design Patterns

(Chris Devlin) #1

370 | Chapter 10: State Pattern


In addition to the classes that make up the State design pattern, you will need a copy


of theNetBtnandBtnStateclasses shown in Example 10-11 and Example 10-12. In


fact, in all the examples in this chapter, theNetBtn.as and BtnState.asfiles will be


required in the same folder as the other files. In subsequent listings, we didn’t


include the listing for the class because they’re all identical. (That means once you’ve


entered it, you don’t have to do anything else with it.) So keep the files handy, and


make sure that they’re included in the folders with your other classes.


public function startPlay(ns:NetStream,flv:String):void
{
state.startPlay(ns,flv);
}
public function stopPlay(ns:NetStream):void
{
state.stopPlay(ns);
}
public function setState(state:State):void
{
trace("A new state is set");
this.state=state;
}
public function getState( ):State
{
return state;
}
public function getPlayState( ):State
{
return this.playState;
}
public function getStopState( ):State
{
return this.stopState;
}
}
}


Example 10-11. NetBtn.as


package
{
//Button for transition triggers
import flash.display.Sprite;
import flash.display.SimpleButton;
import flash.display.Shape;
import flash.text.TextFormat;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class NetBtn extends SimpleButton
{
public function NetBtn (txt:String)


Example 10-10. VideoWorks.as (continued)

Free download pdf