Saving cookies with actionscript 3.0 SharedObject
February 20th, 2009, by Bodie Leonard

Saving cookies with actionscript 3.0 SharedObject

Awesome easy way to save data in a form via actionscript 3.0 SharedObject.
First create a input text field with an instance name of username. Next create a simple button with the instance name of myButton. Lastly copy this code in your actions panel. That easy!

// creating the shared object and nameing it mydata
var myLocalData:SharedObject = SharedObject.getLocal( “mydata” );

//adding event listener to the button
myButton.addEventListener( MouseEvent.CLICK , pressedButton );

// if myLocalData.data is undefined leave the username blank otherwise fill the username with mydata
if ( myLocalData.data.username != undefined ) {
username.text = myLocalData.data.username;
}

function pressedButton ( event:MouseEvent ) {

myLocalData.data.username = username.text;
myLocalData.flush(); // flush is what saves the data to the hard drive
}


2 comments Subscribe Comments

  1. Thanks Bodie for you great example.
    I have been looking on the web for flash AS3.0 sample regarding flash cs3 cookie.
    Your above example above was very helpful to me.
    Oshin Saginian

  2. @ oshin, thank you. I used that example on this site http://theotherwhitemeat.com/porkrecipes/ if you have the “sharedobject” then you bypass the intro otherwise there is an intro that plays and sets the “sharedobject” or cookie


Add your comment

Connect