SharedObject class
Availability: Flash Player 6. Flash Communication Server MX
SharedObject is very powerful: it can provide real-time data sharing services for multiple SWF files and objects posted on local or network. You can see local sharedobject as cookies, and the network's SharedObject can be seen as real time
Data transfer device. The common way of SHaredObject is summarized as follows:
Local data storage This is the easiest way to use SharedObject, this data store does not require Flash servers. For an example: You can call SharedObject.getlocal () to create a sharedObject object to store data. Sharing objects of
The machine is stable. When the operation ends, Flash will store the data to be stored on the user's machine. When running the program next time, the machine will remember the data saved at the end of the last program. Converse, if You should be before the end of the program
SharedObject is set to a null value, then when running this program next time, SharedObject will not store data for last time.
Storage and sharing data on the server, SharedObject can store data on the Flash server, and other client machines can get data stored on the server. For example, you can open a network's SharedObject to store some phone numbers. All customers can watch To. If there is a
Customers have changed data in SharedObject, which can be reflected in the machine of the currently connected user and later connected users. When the client is not connected to the server, these changes will be temporarily stored on the client machine, wait until next time Connect to the service
When the data is transmitted to the server.
Sharing real-time data sharing objects can store data between multiple clients at the same time, such as using shared objects to store the list of connected to the chat room, this list can be opened to all people. If someone enters and flows and shares the object It is updated and changed people
List data is shared by each person.
The following example will demonstrate how to use a shared object in an ActionScript environment, please note that if you want to create a network shared object, you first use the RTMP protocol to connect to Flash's Communication Server:
// Create a local shared object var local_so: SharedObject = SharedObject.getlocal ("foo");
// Create a remote shared object that is not persistent on the servervar my_nc: NetConnection = new NetConnection (); my_nc.connect ( "rtmp: //server.domain.com/chat/room3"; var remote_so: SharedObject = SharedObject. GetRemote ("Users", my_nc.uri; transote_so.connect (my_nc);
// Create a Remote Shared Object That Is Persistent on the server // But not on the client_nc: NetConnection = New NetConnection (); my_nc.connect ("RTMP: //server.domain.com/chat/room3"; var Remote_so: SharedObject = SharedObject.getRemote ("Users", my_nc.uri, true); transote_so.connect (my_nc);
// Create a Remote Shared Object That Is Persistent on the server // and on the clientvar my_nc: NetConnection = new netConnection (); my_nc.connect ("RTMP: //server.domain.com/chat/room3"; var remote_so : SharedObject = SharedObject.getRemote ("Users", my_nc.uri, "/chat") ;Remote_So.connect (MY_NC); data is created and stored in the shared object in the" Data "property of the shared object, each An attribute corresponds to a variable. For example, the three variables are assigned to the shared object .my_so.data.userid = "myLogonname"; my_so.data.currentstatus = "in a meeting"; my_so.data.lastlogon = "february 27 2002 "; When a customer changed a data, all the variable values related to shared objects and the variable values that are transmitted to the server and all other connections to the shared object. So, the amount of information containing a variable, when it The network resources to occupy when changing
More.
For example, a shared object has the following attributes stores a variable: my_so.data.year.month.dayofmonth = SomeValue;
Even if a customer changed any of the age, month, and day, this variable is changed,
Compare the following data structure, and store the same information above, the different is parallel to define three variables to replace the previous one: my_so.data.year = SomeValue; my_so.data.month = SomeValue; my_so.data .dayofmonth = SomeValue;
In this example, a small piece of information is stored in each variable, so when you change one of the properties, the bandwidth is less. You can use the network sharing object you create the real-time update data. Borrowing this method, refining the amount of information of the data can improve performance. Such data design can also reduce data conflicts (may have multiple users to modify a variable)