
FlashCookie7 lets you store small cookie-like data on user's computer. When your website/application needs, you can retrieve previously stored data from user's computer easily. FlashCookie7 is a wrapper class for Flash SharedObject class. But FlashCookie7 has a simpler implementation and usage.
The main advantages of Flash cookies are:
The main advantages of FlashCookie7 are:
Lets start with simplest example.
import com.muratsalma.utils.FlashCookie7; // importing class var fc:FlashCookie7 = new FlashCookie7('CookieFilename'); // creating an instance of class named fc fc.data.username = 'usernameToStore'; // creating a property on 'data' object of fc.
Then, when user closes webpage or swf, FlashPlayer automatically saves all data to a file named 'CookieFilename.sol' (extension automatically added by FlashPlayer). During construction, if a cookie with the specified filename exists then it will be loaded else, a new cookie file with this filename will be created.
To get data from cookie another time:
import com.muratsalma.utils.FlashCookie7; // importing class var fc:FlashCookie7 = new FlashCookie7('CookieFilename'); // notice that we're loading same file trace(fc.data.username); // outputs: 'usernameToStore' so simple.
By default all cookies are categorized by domain, pathToFile and creator swf's filename. So, if moviea.swf creates a cookie named 'cookiea', movieb.swf can't read this cookie even if you specifiy same filename whlie construction. You can specifiy a second parameter to load a cookie for a certain path. Simplest way to make all movies under your domain read/write into same cookies is to specifiy a path parameter during construction. So all cookies will be stored in same path and optionally same filename.
For moviea.swf under any path at your domain:
import com.muratsalma.utils.FlashCookie7; var fc:FlashCookie7 = new FlashCookie7('myCookie', '/'); // notice second parameter. cookie is stored in root level of domain. fc.data.username = 'exampleUser';
For movieb.swf under any path at your domain:
import com.muratsalma.utils.FlashCookie7; var fc:FlashCookie7 = new FlashCookie7('myCookie', '/'); // notice second parameter. cookie is stored in root level of domain. trace(fc.data.username); // outputs: 'exampleUser'
You don't have to save (invoke fc.save() method) your data. FlashPlayer automatically saves all data. But sometimes you must call save() method manually to write all data to disk immediately and make sure your data is on the disk. By default, FlashPlayer provides 100 KB of storage space per domain. But if size of your data is bigger than this, you must increase storage limit. Storage limit increment occurs after user grant. So a user response is required. If your data is bigger than 100 KB and if you don't call save() method, your data will be lost in the end of session, because user did not grant storage limit incremet. Optionally you can specifiy a minimum space reqirement and a callback function to save() method. Important: If you want to ask user for more storage space, your swf size must be 215x183 px at least to display confirmation dialog.
Please see attached sample Flex Application and documentation in ASDoc format for more details.
| File | Size |
|---|---|
| 3.3 KB | |
| 77.59 KB | |
| 1.97 MB |
Post new comment