In this tutorial, let us see how to use Shared Objects in Actionscript 3.0
Flash CS3, AS 3.0
Shared Objects are used to store information on the user machine. For example, you can store your website template settings. The data will be stored till the user clears his/her temporary memory of the machine.
In this example let us store a string in the user machine and we will retrieve it using shared objects.
In the below example after saving a data, refresh the page and click on retrieve button to get the saved data.
Demo:
Download Source Files
Concept:
1. Declaring Shared Object,
var myso:SharedObject;
2. Creating shared object on the client local machine..
myso = SharedObject.getLocal("myApp");
"myApp" is like unique ID, it has to be different for each flash applications you develope. We will access the values using this ID.
3. Storing data to shared object..
myso.data.val = "Data to be Stored";
"val" is the variable name.
4. Delete Shared Object..
delete myso.data.val;
5. Closing shared object..
myso.close();
After the Shared Object has been used, its wise to close it.
- End of Tutorial
Labels: ActionScript 3, Flash
Read more!
|