Appendix C. The ElectroServerAS Object


Click-and-Drag Actions

Methods and Properties of ElectroServerAS

The ElectroServerAS object allows you to easily create chats, multiplayer games, and any other types of multiuser entertainment applications you are interested in developing. It is an ActionScript object that has tons of properties and methods to make your job as a Macromedia Flash developer much easier. With this object, you do not need to write a single line of XML to talk to the ElectroServer socket server; it does that for you!

For instance, if you want to send a chat message, all you need to do is execute a line of ActionScript like this:

 ElectroServerAS.sendMessage(info, "room")  

The info variable contains the message you wish to send. The second parameter, "room," specifies whether you want to send the message to the room at large or as a private message to another user. When this line of ActionScript is executed, the ElectroServerAS object takes the information passed in, determines which XML tags are necessary, formats the data, and sends it to the server.

But the ElectroServerAS object can do more than just send and receive messages. It can create variables at the room level on the server itself. Also, to make multiplayer games easier to program, we have enabled the ElectroServerAS object (with the help of the WDDX_ms.as script, created by Branden Hall of Fig Leaf Software) to send objects to other users. This is a big advantage over other multiuser server systems (server and Flash client working together), because it means that when a player makes a move in a game, instead of having to format an awkward string or XML packet with a zillion attributes, she can just send the object itself. Also, if you find it useful, which I'm sure you will, you can create variables in a room on the server. Whenever these variables are created, updated, or deleted, everyone in the room is informed. This makes creation of a card-based game like poker or hearts (which involves shuffling the deck and informing the players of the card arrangement) more elegant. Without this feature, you'd need a round-robin type of procedure which I find very annoying in which everyone messages everyone else privately. Room variables get around this and enable some really cool possibilities in games.

Earlier, I mentioned that ElectroServer's ability to send ActionScript objects to other users gives it a great advantage over other multiuser servers. I want to also make it clear that there is nothing keeping other multiuser servers from doing this, since it is actually a feature of the ElectroServerAS object and not the socket server. If you use a socket server other than ElectroServer, you can add this ability yourself, but it will take quite a bit of time to write.

graphics/tip_icon.gif

You can certainly develop chats and multiplayer games without the use of the ElectroServerAS object, but it would require a lot of work writing and parsing XML documents as well as numerous hours of debugging.


In order to use much of the ElectroServerAS object's functionality, you must understand event handlers. An event handler is a function that is called when an event occurs. There are many multiuser events that can occur, such as receiving a chat message, receiving a move in a game, receiving an update of the room list, and receiving a game challenge from another user. While you probably won't ever need to use all of the methods and properties ElectroServerAS offers, you will want to know they are there and how to use them. In this appendix we will list and describe every method and property of the ElectroServerAS object.

Evolution Is Ongoing!

Just as with every innovation that makes our lives easier, we are always finding new ways to increase the usefulness of the ElectroServerAS object. To download the most recent version of this object (and any gulp bug fixes or documentation fixes), please visit Electrotank's ElectroServer page (www.electrotank.com/ElectroServer).

graphics/cd_icon.gif

In the AppendixC folder on the CD-ROM, you'll find two functional chats that were created using the ElectroServerAS object. Chat_fullfeatured.fla has all the features of a good chat. Chat_barebones.fla has the absolute minimum features needed to create a working chat.



Macromedia Flash MX Game Design Demystified(c) The Official Guide to Creating Games with Flash
Macromedia Flash MX Game Design Demystified: The Official Guide to Creating Games with Flash -- First 1st Printing -- CD Included
ISBN: B003HP4RW2
EAN: N/A
Year: 2005
Pages: 163
Authors: Jobe Makar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net