This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Cookie Policy. X

Cookies in Flash [basic]

Anyone who regularly browses the Internet is surly aware of so called "cookies", or at least heard about them. Cookies are small pieces of information stored on the user's computer, such as passwords or site's settings (look and behavior). Flash isn't an exception here and does support a similar functionality that is called Shared Objects which allows us to store up to 100Kb of data (more requires user's permission).
Each cookie can be created (or restored) with just one simple line of code:
var soData:SharedObject = SharedObject.getLocal("MyCookie","/");
"MyCookie" is the name of the cookie - if there is already one with that name it will be loaded back into the memory.
Now that the Shared Object is created we can write to it whatever we what, all through the "data" field: = "Hello world!" = 1337;
Similarly, if we want to read from the Shared Object:
trace(; //1337
To make things even simpler all that data is being stored on user's computer automatically, but if needed there is also an option to save it manually by calling the flush() function, which also allows to set the upper limit of cookie's size, making it possible to go over the 100Kb limit by prompting the user for more storage.
Example usage:
(Refreshing the page will save the message and then restore it to the upper text field)