Shared local objects
When I read Advanced PHP for Flash, I was first introduced to local shared objects in Flash and have been in love with them ever since. Last night I set up a shared local object for my electronic music quiz to give users the option of remembering their login information. It is very, very simple to do this. During login state initialization, I have this code:
login_so = SharedObject.getLocal('quizLogin');
if (login_so.data.username != undefined) {
username_txt.text = login_so.data.username;
password_txt.text = login_so.data.password;
}
First, I access the shared object ("so"), whether it already exists or not. If the so's data contains a variable named username, I fill in the username and password information that has been stored previously on the user's machine.
At login, I store in the so the username and password the user entered to be accessed the next time the user visits. This is done like so:
login_so = SharedObject.getLocal('quizLogin');
login_so.data.username = username_txt.text;
login_so.data.pass = password_txt.text;
login_so.flush();
And that's it! You might want to put in some conditionals and let the user decide whether to save the login data to a shared object or not. But the shared object code alone really is that simple.





posted
by Vera (