Now that the structure can support a simple FLV playback system, the next step will be to add two additional states and see if the state machine can be adapted to a Flash Media Server application. Keeping the focus on the design pattern, only two new states will be added—Record and Append.
Changing from a Flash application to a Flash Media Server 2 (FMS2) application requires key changes in the FLA script to include a connection to the server, and adding Camera and Microphone objects. Otherwise, you'll find that adding the additional states of Record and Append are relatively simple.
Adding states is relatively easy, as you've seen. However, when you add Flash
Media Server 2, you need to take care of a few matters to make sure that your
application works correctly. Because AS 3.0 and Client-Side ActionScript (CSAS)
used in FMS2 are a bit different, you need to import the
net.ObjectEncoding class. By doing so,
ActionScript 3.0 and CSAS can work together. The ActionScript 3.0 default Action
Message Format (AMF) is AMF3, but FMS2 needs AMF0. So, you need to change the
ObjectEncoding class to AMF0 using the
This line needs to be in your implementation of the State design pattern, but not in the classes that make up the pattern. (See Example 10-27)
You will see in the
StopState class we made
for this application (Example 10-21 ...