Ask an FMS Guru #3: How do I access a shared object on the server side that was created on the client side?
So here's an interesting question that to most intermediate to advanced people in FMS would consider quite easy, but taking myself back to my younger days in programming I too would have scratched my head.
So here's the Q: How do I access a shared object on the server side that was created on the client side?
Answer: Any remote shared object that is created on the client side can be accessed just the same on the server side. Meaning that it doesn't matter which side you create it on, you can still access it from the other side.
There is one gotcha that I have to mention because this catches so many.
When creating the SO on the client and server side remember to keep your persistance value the same. Which by the way you are only just creating a pointer to the shared object on the server. You aren't actually recreating the SO when you make another reference on the server or client side after creating it on the other.
A quick example to make it all clear.
On the client side you would do it like this (nc is the netConnection object already connected up by the way):
var mySO = new SharedObject.getRemote("SO_name_goes_here", nc.uri, false);
As you can see above with the final "false" value, I've created a non persistant Shared Object, meaning that it gets deleted when nobody is connected to it. A persistant SO gets saved as a file on the server in the application directory.
Now, the gotcha is that on the server side, some will do this:
var mySS_SO = SharedObject.get("SO_name_goes_here", true);
As you can see above, I've written "true" for the persistance value. Even though the SO name is the same as the client side one, because the persistance value is different the SO is completely different. It would have to be written like this to make the server side get the same SO as the client side:
var mySS_SO = SharedObject.get("SO_name_goes_here", false);
So with the above code, I can access the data in the shared object from the server or client side. Both can take advantage of the send() method and of course onSync(). Handy stuff I think.
I hope that helps somebody :)
I think this almost calls for a quick tute on the pros and cons for managing SO's on the client and/or server side... hmm..
Posted by Graeme at February 14, 2006 03:39 AM