"Lou Montulli, the protocols manager in Netscape's client product division, wrote the cookies specification for Navigator 1.0, the first browser to use the technology. Montulli says there's nothing particularly amusing about the origin of the name: 'A cookie is a well-known computer science term that is used when describing an opaque piece of data held by an intermediary. The term fits the usage precisely; it's just not a well-known term outside of computer science circles.'"
In the broadest sense, a cookie allows a site to store state information on your machine. This information lets a Web site remember what state your browser is in.
Haven’t we wished that you had some feature that enables you to store and retrieve cookies in Flash? In fact you can.
It is called SharedObject
mySharedObject = SharedObject.getLocal( objectName [, localPath ])objectName can be a text string(excluding ~ % & \ ; : " ' , < > ? # and SPACE). You can also use “/” in the objectName. Eg:
myso = SharedObject.getLocal( “fuel”); //creates a local storage file called fuel.sol
myso = SharedObject.getLocal( “fuel/rajesh”); //creates a folder called #fuel and local storage file called rajesh.sol within that.
You can use the same objectName in different movie swfs. Using the same name won’t clash the objects. This is because, Macromedia stores each object within a folder by the name of that movie. That is, a getLocal call from nav.swf is stored in a folder nav.swf (full file name, with extension, is used for folder name).
mySharedObject.flush([ minimumDiskSpace ])
Immediately writes a locally persistent shared object to a local file. If you don't use this method, Flash writes the shared object to a file when the shared object session ends—that is, when the SWF movie is closed. If you set the optional minimumDiskSpace (integer), that much byte will be allocated for the file. By default it is zero.
If flash was able to store the data, this method returns true or else false.
If the disk space usage exceeds allocated size for the website, flash pops up a window and asks the user to allocate/de-allocate disk space for the site. While the window is open, the flush() method returns a “pending” value.
The user is able to manage the disk space allocation for the storage file. By default, Macromedia Flash MX can save locally persistent remote shared objects up to 100 K in size. When you try to save a larger object, the Macromedia Flash Player 6 displays the Local Storage dialog box, which lets the user allow or deny local storage for the domain that is requesting access. Make sure your Stage size is at least 215 x 138 pixels; this is the minimum size Macromedia Flash MX requires to display the dialog box.
mySharedObject.getSize();
This method returns the current size of the shared object, in bytes.
mySharedObject.data
This property is used to store and retrieve data in the local storage.
Eg:
visitedArray = new Array();
visitedArray[0] = 1;
visitedArray[1] = 0;
visitedArray[2] = 1;
visitedArray[3] = 1;
mySharedObject.data.userName = “Rajesh”;
mySharedObject.data.languageID = “1033”;
mySharedObject.data.lastUnitVisited = “m2p3u2”; //stores text
mySharedObject.data.progress = 20; //stores numeric
mySharedObject.data.visitedUnitsArray = visitedArray; //can store arrays as well!!!
mySharedObject.flush();
mySharedObject.onStatus
mySharedObject.onStatus = function( infoObject ) {
//add code to trap the error
}
onStatus Event handler is invoked every time an error, warning, or informational note is posted for a shared object. If you want to respond to this event handler, you must create a function to process the information object generated by the shared object. infoObject parameter contains the status message information.
"status" , "warning" , or " error" are some of the common infoObject parameters. Apart from that, some class/methods return additional information.
Eg:
mySharedObject.flush.Failed // A SharedObject.flush command is returned when "pending" has failed (the user did not allot additional disk space for the shared object).
mySharedObject.Flush.Success //A SharedObject.flush command that returned "pending" has been successfully completed (the user allotted additional disk space for the shared object).
Important: This works with FlashPlayer 6 and above. Also the user needs to allow adequate local storage permission.
Friday, September 24, 2004
Subscribe to:
Posts (Atom)