O'Reilly logo

ActionScript 3.0 Design Patterns by Chandima Cumaranatunge, William Sanders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding More States and Streaming Capabilities

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.

Setting Up Your ActionScript 3.0 Script for FMS2

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 line,

NetConnection.defaultObjectEncoding=flash.net.ObjectEncoding.AMF0;

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required