
94
Understanding naming conventions for remote shared objects.
To avoid name collisions, Flash
looks at the location of the movie that is creating the shared object. For example, if a movie at
www.myCompany.com/apps/stockwatcher.swf creates a shared object named
portfolio, that
shared object will not conflict with another object named
portfolio that was created by a
movie at www.yourCompany.com/photoshoot.swf, because the movies originate from two
different directories.
However, if two different movies located in the same directory create objects with identical names
and the same location for
persistence, the names will conflict, and one object can overwrite the
other without warning. Implemented properly, however, this feature lets movies in the same
directory read each other’s shared objects.
Similarly, you can use
persistence to let movies in different directories in the same domain read
and write each other’s shared objects. For example, if the full path to the SWF file is
www.macromedia.com/a/b/c/d/foo.swf,
persistence can be any of the following:
• "/"
• "/a/"
• "/a/b/"
• "/a/b/c/"
• "/a/b/c/d/"
• "/a/b/c/d/foo.swf/"
By specifying a partial path for
persistence, you can let several movies from the same domain
access the same shared objects. For example, if you specify "/a/b/" for the movie named above and
also for a movie whose full path is www.macromedia.com/a/b/foo2.swf, each movie can read
shared objects created by the other movie. When specifying
persistence, do not include a
domain name.
To specify that the path for
persistence should be the same as the movie, without having to
explicitly specify its value, you can use MovieClip._url:
myRemoteSharedObject = (name, uri, _root._url);
Example
The following example illustrates the sequence of steps required to create a nonpersistent remote
shared object.
// open connection to server
nc = new NetConnection();
nc.connect("rtmp://myServer.myCompany.com/someApp");
//
// the URI for the shared object must be the same as
// the URI of the NetConnection it’s using
mySO = SharedObject.getRemote("myObject", nc.uri);
mySO.connect(nc);
See also
NetConnection (object), SharedObject (object), SharedObject.connect,
SharedObject.getLocal, SharedObject.onSync
Commentaires sur ces manuels