SharedObject Events


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.

.onStatus

onStatus 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."

.onSync

onSync 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 Components

Let'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:

  1. Open the folder containing the applications on the Flash Communication Server.

  2. Create a new application folder called mySharedApp.

  3. Copy the file main.asc you created in the mySecondApp folder. If you didn't create that file, refer to Chapter 6, "STEP 6: ActionScript with NetConnection()," for the details of that file.

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:

  1. Open the work file WhiteCursor.fla in Flash MX.

  2. Drag the Cursor UI component from the Communication Components panel (Ctrl+F7) to the Flash stage. This adds a dot to the screen. It doesn't matter where the dot is. It represents an "empty" MovieClip.

  3. Click the Cursor dot and give it the instance name cursor_mc in the component Properties window.

  4. Create a new layer on the Timeline.

  5. Drag the new layer to the bottom of all other layers . This layer will be used for the Shared WhiteBoard. You must put it on a layer "under" the other objects on the Flash stage.

  6. Click the first frame of the new layer.

  7. Drag the WhiteBoard component to the Flash stage.

  8. Name the component whiteboard_mc. Make sure you select it first to see the component properties!

  9. Set the following properties in the Properties window to make the WhiteBoard full screen:

    W: 550

    X: 0

    H: 400

    Y: 0

  10. Open the ActionScript panel (F9) and click on the frame containing the ActionScript (default: Frame 1; Layer 1).

  11. Change the application reference from mySecondApp to mySharedApp in the NetConnection string. Confirm the ActionScript with Listing 8.1.

    Listing 8.1 Completed ActionScript Listing for WhiteCursor.fla
     // create a new instance of the NetConnection object myConnection_nc = new NetConnection(); // handle any status changes and responses from the server myConnection_nc.onStatus = function(info) {       trace("LEVEL: "+info.level+"  CODE: "+info.code); }; // connect the application when the Login button is pressed appLogin = function () {       // Make the connection to the server       myConnection_nc.connect("rtmp://192.168.0.112/mySharedApp/myInstance", login_txt. graphics/ccc.gif text);       // Connect the UI Components to the new connection       peopleList_mc.connect(myConnection_nc); }; connectionLight_mc.connect(myConnection_nc); 
  12. Connect the Cursor and WhiteBoard components with the myConnection_nc connection. Place the following code under the peopleList_mc connection line:

     cursor_mc.connect(myConnection_nc);  whiteBoard_mc.connect(myConnection_nc); 
    Figure 8.1. The WhiteBoard and the Cursor UI components use SharedObject to display their activity on remote computers.

    graphics/08fig01.gif

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.



Macromedia Flash Communication Server MX
Macromedia Flash Communication Server MX
ISBN: 0735713332
EAN: 2147483647
Year: 2002
Pages: 200
Authors: Kevin Towes

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