10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ActionScript</strong> <strong>3.0</strong> and CSAS can work together. The <strong>ActionScript</strong> <strong>3.0</strong> default Action<br />

Message Format (AMF) is AMF3, but FMS2 needs AMF0. So, you need to change<br />

the ObjectEncoding class to AMF0 using the line,<br />

NetConnection.defaultObjectEncoding=flash.net.ObjectEncoding.AMF0;<br />

This line needs to be in your implementation of the State design pattern, but not in<br />

the classes that make up the pattern. (See Example 10-27)<br />

You will see in the StopState class we made for this application (Example 10-21) we<br />

need to have a key difference in the way that the NetStream.play( ) method is<br />

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

a CSAS method. However, because the flash.net.ObjectEncoding has been<br />

imported, the two different versions of <strong>ActionScript</strong> can work together.<br />

Flash Media Server 2 is an open socket media server available from<br />

Adobe. You can download the Developer’s Version free from<br />

http://www.adobe.<strong>com</strong>/products/flashmediaserver/<br />

You will need to set it up in a Windows or Linuxserver environment,<br />

or just on your own <strong>com</strong>puter with Windows OS. On a Macintosh,<br />

you’ll need to be in the Windows mode to set it up.<br />

Once installed on your system, just add a folder named flvstate in the applications<br />

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

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

application. (You’ll need to follow the FMS2 documentation for the setup.)<br />

The Adaptable States<br />

The first task when working with state machine models is to update the model.<br />

Figure 10-7 shows the addition of two new states—Append and Record. The original<br />

three states are pretty much the same as before. Note that the Stop state is the<br />

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

state except Pause, the transition must first go to the Stop state.<br />

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

adding two more states, Append and Record, all the other states and contexts need<br />

to be changed as well. However, you don’t have to change a huge number of conditional<br />

statements. The testing application also needs changes, but because that code<br />

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

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

necessary changes for the state machine:<br />

Adding More States and Streaming Capabilities | 383

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!