FlashSim Interactive Simulation Newsletter

Vol. 2, No. 2 (March, 2004)
This Edition's Contents:
This newsletter is brought to you by Jonathan Kaye and David Castillo, the authors of "Flash MX for Interactive Simulation," the first practical guide to building interactive product simulations and performance-based training in Flash.

A number of people have written to us asking about when our book materials (components, state engine, and tools) will be available in Flash MX 2004. Today's the day for our state engine and tools (our components are coming along soon)!

Since this is a big deal for us, this edition of the newsletter is devoted to introducing the engine to you.

We've put our heads down in the last month and a half to study up on AS 2.0 and get our work converted. As a subscriber to this newsletter, you can download our state engine, which is accompanied by our run-time state visualization tool and our statechart-XML-to-code generator (remember that from our January 2004 newsletter?).

We're still putting the final touches on our AS 2.0 components, which will be ready soon. We'll send out an announcement when they are available, but since it took quite an effort to convert and upgrade our component set, and to write full documentation via the Help panel, we will be selling them. The components have been tested with the Flash Player 7 as well as being backward compatible to the Flash Player 6 r65.

As always, your comments and feedback are welcome.

Jonathan & David

 
 
LET US HELP YOU WITH YOUR PROJECTS
If you have an interactive-simulation problem or project you would like to discuss with us, please email us and we'd be happy to help you. Through our company, Amethyst Interactive LLC, we offer customized workshops and project assistance to get your projects done quickly and correctly!
 
ADVERTISEMENT
 
 
THE AS 2.0 STATE ENGINE (FStEng v1.5)

This month's download is a a ZIP file containing the AS 2.0 state engine and tools, an example TestCases file to show how to use the engine, and the book's Stolex watch implemented using that code.

Sign up now and get access to download the code through the subscriber's edition!

We have completed our port of the original Flash MX state engine (FStEng v 1.5) to AS 2.0, and added some tools into the distribution for helping to build programs using the state engine. This package can be downloaded by clicking on the link in the box on the right.

Once you have installed the MXP using the Macromedia Extensions Manager, you are ready to go. Any code you have written for the Flash MX version will work identically in the Flash MX 2004 provided that you add the following line to the top of the script in which you build your state machines:

import mx.fmxis.FStEng.OneFive.*;

The API is identical to the API for our Flash MX version. The main difference between these versions is that the Flash MX 2004 version does not have a component tile that you drag into your current movie--you simply start declaring your state engine (stateEngine), and Flash automatically pulls in the code from its installed location within the Flash install directory, inside Classes > mx > fmxis. The statement above tells Flash to look in this folder for the class definitions.

Our AS 1.0 components do not work with AS 2.0, so we have updated all of our components (you'll see a couple of them in the downloadable Stolex watch example files). With the book's components, we hardcoded communication with an ieh() method, since we used the components with our engine's internal event handler (ieh). In our AS 2.0 components, however, we used Macromedia's approach to events/listeners, in which you can subscribe to individual events or define a method handleEvent() to catch all events. Also, the parameter passed to an event handler is now an event object rather than the individual message and value we passed before. Therefore, if you use our AS 2.0 components with the state engine, you'll need to add the following:

myEngine.handleEvent = function (ev) {
this.ieh(ev.type, ev.val, ev.target);
}

Included in the distribution is our TestCases.fla movie, which shows you how to code different configurations of state machines.

Note: Coding in AS 2.0, you can now declare the types of variables, such as

var myState:state = new state("state1", 0, myMgr);

However, you will get a compile error if you try to define an internal event off the state, is in

myState.onLeftButtonPress = function () ...

because the state class is not declared dynamic. Here are some solutions:

  1. Remove the type restriction from the variable. You will lose the checking, which is bad.
  2. (Purist approach) Subclass the state class with a new class of your own that declares the methods (such as onLeftButtonPress) you will use. This is the purist approach, but can be very time consuming because you need to declare any method that any state might declare.
  3. Go into your Flash install directory then Classes > mx > fmxis > FStEngOneFive and change the state class definition to dynamic, as in

    dynamic class state { ...

     

Help Panel Documentation

While the engine is hard to apply without our book, even when you have the book you have to flip back and forth between the reference and your code. To alleviate this, we have created full help panel documentation and code hinting. You can see on the left of the figure below that we provide documentation for all public events, properties, and methods for all core state engine classes.

RTVis

The figure above is a snapshot from the help panel screen for our run-time visualization tool. This tool, nicknamed RTVis, dynamically reads the structure of your state machine and displays it in a tree view component. As your program executes, RTVis automatically updates the view regarding the current state(s).

RTVis is a component located in the RTVis folder within the Component Panel. It appears as a pop-up window above your content on the Stage. You can inspect the run-time state of your state engine by entering the full name and path (from _root) of the state engine. For example, if your engine is defined within a movie clip instance named "myInterfaceClip", and your engine was defined as "myEng = new stateEngine(...);", then you would enter "myInterfaceClip.myEng" into the provided text field, and then press "Load Engine". RTVis will read the structure and display the current state(s), if the engine is currently activated (if it is not, RTVis will still show the structure).

When you are finished using the tool, we recommend that you delete it from your Library so that it does not bring in superfluous data before the first frame, even when it does not exist on the Stage. See the help panel documentation for more information.

Example

For those of you who have attended our workshops and have built the simple traffic light, we have extended the development to include a more sophisticated pedestrian crossing system, as illustrated below. We can't give you the code, but if you visit this page you will see more information and we give you the XML statechart description of the traffic light system.

The pedestrian crossing system was built using the AS 2.0 version of FStEng 1.5, and the cars were built with the AS 2.0 version of Miro Samek's QHsm (from the November 2003 newsletter). If you want to learn how to code these, attend one of our workshops!

Statechart XML to Code Now Within Flash MX 2004 Environment

In the January 2004 newsletter, we gave you a simple tool we built that generates FStEng v1.5 code from an XML description of the state engine. We have taken this tool on step further and packaged it into the Flash MX 2004 environment directly. Once you install the provided MXP, the tool is available in the Windows > Other Panels > Statechart XML to Code menu:

When you call up this window, you will see the following:

Follow the three steps to produce code from an XML description. You can paste or type the XML directly into the text box below step 1, or press "Select XML File" to have Flash bring up a dialog box that lets you choose the file from your hard drive or network (by the way, if you are interested in the source code to see how this is done, please click here).

Once you have generated the code, the program will tell you whether or not there were errors produced in translating the XML to code. If there were errors, the program puts comments with "ERROR" at the line it found the error. In any event, you can copy all the generated code (Ctrl+A) and paste it into the keyframe you want.

We have included two examples in the Help book for this tool, so you can copy and paste them into the box under Step 1 and see the code generated. The first example is the infrastructure for a simple traffic light, and the second is the complete XML specification for the Stolex watch interface.

For more information, please ask us a question on our discussion boards!

 

BACK TO TOP

 
UPCOMING EVENTS
 
Do you know about a simulation event you'd like to announce? Tell us about it at events@FlashSim.com!
Date Event Location
April 7-8 NASA's Smart Medical Technologies Summit Houston, TX
June 14-18 AICC meeting San Francisco, CA
     
We are looking across the country for locations to host our 1-day public developer workshops. Our current focus is the Bay (San Francisco) area. Please let us know of your interest in attending these workshops!
 
YOUR OPINION COUNTS
 

Note: While we encourage you to join the discussion, we feel we've heard enough about making money fast, cheap or natural Viagra, African dignitaries wanting to give us money, low cost insurance, penis enlargement, dates for married men, Russian girls waiting to hear from us, reducing wrinkles, tips for exploding our income, and losing weight rapidly. So if your post was going to be about one of those or along a similar vein, please post somewhere else. On the other hand, if you need any of these services, I'm the man to talk with!

Jonathan

We constantly run into all different people around the country and world who have interesting simulation projects they have in mind or have prepared. We want to encourage you simulator programmers, instructional designers, gamers, managers, and other developers to share your stories and best practices with the rest of us. We invite you to lead or join the discussion on our FlashSim discussion board:

http://FlashSim.infopop.cc/

We also will monitor the discussions for particular topics that might make good newsletter information, so go forth and post!

If you have suggestion for topics you'd like to see in the newsletter, or links to events or interesting Flash pieces you've made, please email us at newsletter@FlashSim.com.

 
ADMINISTRATION

This newsletter (in public form) also is available on FlashSim in the RESOURCES section:
http://www.FlashSim.com/newsletter/v2n2.html

If you'd prefer not to receive this newsletter, send us your name, your registered e-mail address, and the message: "Unsubscribe" to removeListener@FlashSim.com.

If you are receiving this newsletter from a friend and want to subscribe yourself, please email us a message with the subject "Subscribe" to addListener@FlashSim.com.

 
 
All content © 2000-4 Equipment Simulations LLC