Tue Feb 16 06:04:06 2010
For anyone making applications using ActionScript 3.0, SharedObject is an absolute must! It allows data to be stored inside the flash player itself, meaning applications you create do not have to reply on browser cookies, and thus there is no worry of browser cookies being deleted or the hassle of writing a program in something like PHP to store your data on a database for example... although that may be a little more efficient especially if you are writing something that stores long-term data.
To use SharedObject, all you have to do is create a variable and datatype it to
SharedObject. Don't forget to import
flash.net.SharedObject if you haven't already. Take at the variable below.
var myData:SharedObject = SharedObject.getLocal("data");By setting the SharedObject it will automatically be created by the Flash Player. There are no further steps involved in creating this data so it's quick and easy.
The SharedObject will accept all kinds of data including numbers,
strings, arrays, etc. When data is not already set inside your SharedObject, it will return
undefined. For example, I have yet to set any data in the variable 'myData' that I created earlier and so if I tried to trace any data I would get
trace("My data : "+myData.data.mySetData); //traces My data : undefinedIf I were now to actually set data and then trace it, SharedObject would return that data back to me.
myData.data.mySetData = "I set this."; trace("My data : "+myData.data.mySetData); //traces My data : I set this
Additionally, you can clear any data set by calling the
clear() method on your variable.
myData.clear(); trace("My data : "+myData.data.mySetData); //traces My data : undefined
Naturally, that is not all there is to know about SharedObject, but it should be enough to get those who are not yet savvy about this on their feet. As a side note, this has been around for quite sometime and those game creators who haven't yet checked this out should definitely do so.Tweet