Task 2: Storing Local Data
Web browsers are limited in their ability to store data on a user's hard disk. Cookies are often used for this purpose, but individuals can disallow or delete them. Worse, cookies require a page refresh for read/write operations (unless you're using client-side JavaScript).
Flash MX Solution
Local Shared Objects is an undocumented, fully functional feature of Flash MX. A Shared Object is like a cookie except that it can store full ActionScript objects like arrays, rather than simple name/value pairs. Shared Objects are stored in a directory controlled solely by Flash Player. By default, the Player is permitted to store 100 kilobytes worth of Shared Objects, but additional space can be allocated if required.
Unlike cookies, Shared Objects do not carry an expiry date, and do not have an individual size limit.
Try It
To store user login information in a local Shared Object, complete the following steps:
Open a new document, and draw out two input text fields.
Give the text fields instance names: User and Pass.
Select the first key frame of the movie and assign the following ActionScript code:
localSO = sharedObject.getLocal("login"); if (localSO.user != "") { User.text = localSO.data.user; Pass.text = localSO.data.pass; }
Create a new button symbol (to act as a save button), and assign the following ActionScript code to it:
on (release) { localSO.data.user = User.text; localSO.data.pass = Pass.text; }
Export the movie. If the Shared Object is already set, information will be filled into the fields. The information with either be stored or updated when your button instance is clicked. To test that the information was stored, close the movie and run it again.