This chapter is going to demonstrate three different remote shared objects with minimal code. The first will be a pointer that allows you to point to any location on another person’s page. This kind of pointer can come in handy if you’re making a presentation to a remote location and you have to point out different things to the audience. Second, you will see how to make a minimal text chat where the text entered into an input text box shows up on all of the users’ screens. Finally, using a shared movie clip, you will see how to open up web pages on remote viewers’ screens. These are all minimal examples, but they show how you can do different things with remote shared objects. The rest is up to your imagination.
First, though, note that instantiating a shared object is a little different than most class instances. The general format for instantiating a shared object is shown in Figure 4-1.
Figure 4-1.Instantiating ShardObject class
Generally, it’s a good idea to set the scope of the shared object by simply declaring the shared object’s name and data type, such as:
var my_so:SharedObject;
If your declaration is at the top level you can do the actual instantiation in different scopes. If you want to use a single step for the instantiation and declaration, you would use the format:
var so:SharedObjec=SharedObject.getRemote(string,uri);
Setting Up Shared Object Storage: Slots
When you set up a shared object instance, you need to set up a storage system based around the object’s dataproperties. By assigning different attributes to thedataproperty you can create slots using most kinds of data types. The following shows a simple data slot:
var memberName:String= name_txt.text; so.data.nameNow = memberName;
The shared object has adataattribute,nameNow. So it now has a storage slot for a string name that can be shared with others connected to the same application. In the same way, you can set up as many slots as your application needs, using the appropriate data type for the data to be stored.