Nonpersistent Client-Side Remote Shared Objects - Minimalist Project for Shared Movie Clip
(Page 4 of 4 )
The first minimalist project uses a movie clip as a shared object. This one shows how to set up and move a pointer. In creating applications that have online slide shows that work something like a PowerPoint presentation, you need all of the viewers to see the pointer move to the location on the screen where you want the audience to focus. Using a hitchhiker thumb as a pointer, this application has numbers in each of the stage’s four corners. The four numbers are just positions on the stage so that you can see that when you move the pointer on the screen, it will go to the same positions on all of the screens connected to the application. You’ll use these classes and objects for the application:
Classes
NetConnection
SharedObject
Objects
Movie Clip (1)
The following steps will walk you through the project:
- Open a new Flash document and set up the following layers, from top to bottom: Actions, MC, and Background.
- In the Background layer, place a number from 1 to 4 using a 48 point font in each of the four corners of the state as shown in Figure4-2. Lock the layer.
- Select the MC layer and draw a pointer—this can be any shape you want. (The sample in Figure 4-2 shows a hitchhiker’s thumb, but you can use a big arrow or any other pointer shape you want.)
- Select the shape and press F8 to open the Convert to Symbol dialog box. Select Movie Clip and click OK. Select the movie clip on the stage and provide it with the instance namepointer_mcin the Properties panel. Lock the layer.

Figure 4-2. Completed stage
- Click on the first frame of the Actions layer and type in the following script in the Actions Panel:
1 //Connect
2 var rtmpNow = "rtmp:/zbasicSO";
3 //var rtmpNow = "rtmp://domain.name.com/zbasicSO";
4 var nc:NetConnection = new NetConnection();
5 nc.onStatus = function(info) {
6 trace(info.code);
7 };
8 nc.connect(rtmpNow);
9 //Shared object
10 pointer_so = SharedObject.getRemote("point", nc.uri, false);
11 pointer_so.onSync = function() {
12 pointer_mc._x = pointer_so.data.x;
13 pointer_mc._y = pointer_so.data.y;
14 };
15 pointer_so.connect(nc); 16 //Control Shared Object
17 pointer_mc.onPress=function () {
18 this.onMouseMove = function() {
19 pointer_so.data.x = this._x=_level0._xmouse;
20 pointer_so.data.y = this._y=_level0._ymouse;
21 };
22 pointer_mc.onRelease = pointer_mc.onReleaseOutside=function () {
23 delete this.onMouseMove; 24 };
25 };
- If it does not exist already from the previous example, in the server-side FMS2 root, create a new folder and name it zbasicSO.
- Once you have completed the application, publish it (File > Publish). When you test it, you have to open a second window with the same application so that you can see two instances running at the same time. You will see that when you move the pointer on one screen, it also moves on the other.
Note: If you are connecting to an FMS2 server via the Internet, it’s best to upload the files to a web server to avoid running into security issues while testing.
In looking at the code, you will see that the value of the shared object is based on changes in the position of the mouse pointer. Whenever the mouse moves, both the _x and _y values of the mouse position are passed to the shared object data attributes as well as the pointer. Whenever the shared object values change, they trigger theonSyncevent handler that updates the shared object values on all of the connected clients.
Please check back next week for the conclusion to this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |