ActionScript 3.0 Design Patterns

(Chris Devlin) #1
Adding More States and Streaming Capabilities | 383

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


theObjectEncoding 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 theStopStateclass we made for this application (Example 10-21) we


need to have a key difference in the way that theNetStream.play( )method is


employed. By adding a second parameter to the method, it’s effectively changed into


a CSAS method. However, because the flash.net.ObjectEncoding has been


imported, the two different versions of ActionScript can work together.


Flash Media Server 2 is an open socket media server available from
Adobe. You can download the Developer’s Version free from
http://www.adobe.com/products/flashmediaserver/
You will need to set it up in a Windows or Linu xserver environment,
or just on your own computer with Windows OS. On a Macintosh,
you’ll need to be in the Windows mode to set it up.

Once installed on your system, just add a folder namedflvstatein theapplications


folder of the Flash Media Server. Once that’s done, you don’t need to do anything


else with the server other than make sure that it’s running when you use the FMS


application. (You’ll need to follow the FMS2 documentation for the setup.)


The Adaptable States


The first task when working with state machine models is to update the model.


Figure 10-7 shows the addition of two new states—Append and Record. The origi-


nal three states are pretty much the same as before. Note that the Stop state is the


central one for all transitions except for the Play-Pause toggle. To change from any


state except Pause, the transition must first go to the Stop state.


As noted at the outset, statecharts make it easy to see required program changes. By


adding two more states, Append and Record, all the other states and contexts need


to be changed as well. However, you don’t have to change a huge number of condi-


tional statements. The testing application also needs changes, but because that code


is more a user of the state machine than an actual part of the state machine, it will be


handled separately. The following scripts, Examples 10-20 through 10-26, add all the


necessary changes for the state machine:

Free download pdf