|
/* SwishMax and cookies, basics by cybernetix. */
onload() {
mySharedObj = SharedObject.getLocal("swishMaxCookie"); // this will read existing local shared object. if object does not // exist, new one will be created. // mySharedObj - variable, rename it to whatever you want. // "swishMaxCookie" - unique name of file that will be stored localy // on visitor's computer. it would be good to use name of your site // and suffix "cookie" for example: "mySiteCookie".
// IMPORTANT: do not use any of special chars!!! }
onFrame(1) {
createTextField("infoText", 1, 0, 0, 300, 300); // create text filed to display info // now you can examine or create content of cookie.
// var someData = mySharedObj.data.someData; // this will find value of data named someData in sharedobject, // rename someData to whatever you want. see below. var visitCounter = mySharedObj.data.visitCounter; // find number of visits
var visitDate = mySharedObj.data.visitDate; // find date of last visit
infoText.text = "Old datas" + "\n" + "Counter: " + visitCounter + " / Date: " + visitDate + "\n"; // display actual values // now you can change datas in object to some new values
if (mySharedObj.data.visitCounter) { mySharedObj.data.visitCounter += 1; } else { mySharedObj.data.visitCounter = 1; } // increase number of visits for one, if shared object is just // created set visitCounter to 1; dateObj = new Date(); mySharedObj.data.visitDate = dateObj.toString(); // change date to actual date mySharedObj.flush(); // this will save new values to local sharedobject.
}
onFrame(2) {
mySharedObj = SharedObject.getLocal("swishMaxCookie"); // read object again infoText.text += "\n" + "New datas" + "\n" + "Counter: " + mySharedObj.data.visitCounter + " / Date: " + mySharedObj.data.visitDate + "\n"; // display new values
}
/* NOTE: if amount of stored data in cookie is more than 100kb flash player will ask visitor to allow it, otherwise it will work transparently. Also, remember that sharedobjet is not really cookie but it can be used for that purposes as well. So, if visitor's browser is set to block cookies it will not affect to your cookie.
TO ACHIEVE THIS FEATURE YOU MUST EXPORT YOUR APP TO SWF6 OR LATER!!!
---------------------------------------------------------------------
To see this tutorial in action create new swi file, set movie size at least 300x300pix and copy/paste this script into Script panel, set export file to SWF6 or later and test it in external browser. You can try to click refresh button in browser to see how datas change. */
/* SWI FILE AVAILABLE IN DOWNLOAD SECTION. */
|