ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Expanding the State Design: Adding States | 379

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


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


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


additional button are on lines 45-48 and 53. So just edit theTestVid.asfile as shown


in Example 10-19, and save it as TestPause.as.


this.state=state;
}
public function getState( ):State
{
return state;
}
public function getPlayState( ):State
{
return this.playState;
}
public function getStopState( ):State
{
return this.stopState;
}
public function getPauseState( ):State
{
return this.pauseState;
}
}
}


Example 10-19. TestPause.as


1 package
2 {
3 //Implement FMS2 App and Test State Machine #6
4 import flash.display.Sprite;
5 import flash.net.NetConnection;
6 import flash.net.NetStream;
7 import flash.media.Video;
8 import flash.text.TextField;
9 import flash.text.TextFieldType;
10 import flash.events.MouseEvent;
11 import flash.events.NetStatusEvent;
12
13 public class TestPause extends Sprite
14 {
15 private var nc:NetConnection=new NetConnection( );
16 private var ns:NetStream;
17 private var vid:Video=new Video(320,240);
18 private var vidTest:VideoWorks;
19 private var playBtn:NetBtn;
20 private var stopBtn:NetBtn;
21 private var flv:String;

Example 10-18. VideoWorks.as (continued)

Free download pdf