The events of the SharedObject make it unique from any other ActionScript object. There are two events: onStatus and onSync . The onSync method informs each client to update itself with changes or additions made to the remote SharedObject. .onStatusonStatus is just like any other onStatus you have been introduced to. Each time the remote SharedObject receives an error, warning, or other informational note, this event is triggered. The data is received through an information object containing multiple properties including code and level . onStatus can only be overwritten after instantiating the SharedObject, unless you choose to overwrite the prototype. A full listing of all Information objects handled by onStatus is presented in Appendix C,"Information Objects (Server and Client) Quick Reference." .onSynconSync handles announcements sent from the server. These announcements inform the client of changes made to an attribute of the data property. Like onStatus , this event must be overwritten to handle these announcements. The server sends an Information object containing an array of objects that have been changed, added, or deleted. ActionScript must be created to handle these announcements. onSync will be discussed in great detail later in the section "How Does the Shared Cursor Work?". Exercise 8.1: Using the Remote SharedObject with the Macromedia Flash Communication Server MX UI ComponentsLet's jump right into a simple implementation of a remote SharedObject first using some of the Flash UI components that were installed in Flash MX. There is no new scripting involved with the first example. You could even do this using the SimpleConnect component. Following this exercise, you will learn what is happening between the server and the client. You have already used SharedObjects with some of the previous exercises in this book. Did you know the Chat UI component used a persistent SharedObject to store the logs of your chat? This is why you can continue to see the logs, even after reconnecting after a disconnection. Two very obvious implementations of SharedObject can be demonstrated using the Cursor component and the WhiteBoard component. These two objects allow you to see the mouse position of each connected user and draw on each other's Flash player windows . They can both be used with the SimpleConnect component, but to continue with our scripting theme, we will use the Login button you used in the previous examples. First, begin working on the server. Set up a new application folder:
That's all you need to do on the server. This exercise builds on the Step2-multiConnect.fla file you built in Chapter 6 . Copy the file Step2-multiConnect.fla to the new mySharedApp folder (or your work folder) and give it the name WhiteCursor.fla. Use Figure 8.1 as a guide for your layout of the UI components. With the application folder setup, follow these next steps to construct the interface:
These Flash UI components are very easy to connect. You don't even need to use ActionScript if you choose to use the SimpleConnect component. Invite someone to test the movie with you. Publish the movie (F12) and log in to the application. The Cursor component creates a simple "avatar" that represents you on the screen. The WhiteBoard component allows you to collaborate on a drawing. The WhiteBoard is a great starting point for the application. Consider if you placed an image below it. You could build a simple annotation system. If you placed a live video feed under it, you could also annotate live video, while having a conversation with someone. |