Return to Snippet

Revision: 32878
at October 3, 2010 19:23 by carbonr


Updated Code
//create SO
var mySharedObject:SharedObject = SharedObject.getLocal("republicofcode");
mySharedObject.data.firstName = "John";
mySharedObject.data.lastName = "Doe";
mySharedObject.flush();

//Read SO
var mySharedObject:SharedObject = SharedObject.getLocal("republicofcode");
trace(mySharedObject.data.firstName);
trace(mySharedObject.data.lastName);


//Delete SO
var mySharedObject:SharedObject = SharedObject.getLocal("republicofcode");
mySharedObject.clear();


//example for SO where it stored a X & Y coordinates of a movie
////////////////////////////////////////////////////////////////


var mySO:SharedObject = SharedObject.getLocal("republicofcode");

movie_mc.x = mySO.data.my_x;
movie_mc.y = mySO.data.my_y;

if (!mySO.data.my_y) {
movie_mc.x = 150;
movie_mc.y = 100;
}

movie_mc.addEventListener (MouseEvent.MOUSE_DOWN, onDown);
function onDown (e:MouseEvent):void {
var my_mc = e.target;
my_mc.startDrag ();
}

movie.addEventListener (MouseEvent.MOUSE_UP, onUP);
function onUP (e:MouseEvent):void {
logo_mc.stopDrag ();
mySO.data.my_x = movie_mc.x;
mySO.data.my_y = movie_mc.y;
mySO.flush ();
}

movie_mc.buttonMode=true;

Revision: 32877
at October 3, 2010 19:22 by carbonr


Initial Code
//create SO
var mySharedObject:SharedObject = SharedObject.getLocal("republicofcode");
mySharedObject.data.firstName = "John";
mySharedObject.data.lastName = "Doe";
mySharedObject.flush();

//Read SO
var mySharedObject:SharedObject = SharedObject.getLocal("republicofcode");
trace(mySharedObject.data.firstName);
trace(mySharedObject.data.lastName);


//Delete SO
var mySharedObject:SharedObject = SharedObject.getLocal("republicofcode");
mySharedObject.clear();


//example for SO where it stored a X & Y coordinates of a movie
////////////////////////////////////////////////////////////////


var mySO:SharedObject = SharedObject.getLocal("republicofcode");

movie_mc.x = mySO.data.my_x;
movie_mc.y = mySO.data.my_y;

if (!mySO.data.my_y) {
movie_mc.x = 150;
movie_mc.y = 100;
}

movie_mc.addEventListener (MouseEvent.MOUSE_DOWN, onDown);
function onDown (e:MouseEvent):void {
var my_mc = e.target;
my_mc.startDrag ();
}

movie.addEventListener (MouseEvent.MOUSE_UP, onUP);
function onUP (e:MouseEvent):void {
logo_mc.stopDrag ();
mySO.data.my_x = movie_mc.x;
mySO.data.my_y = movie_mc.y;
mySO.flush ();
}

logo_mc.buttonMode=true;

Initial URL

                                

Initial Description
This snippet will help create a flashSharedObject a.k.a Flash Cookie, which much better than conventional cookies since they remain through all browsers and cannot be erased by the user using traditional cookie erasing methods

Initial Title
Create a Flash SharedObject (Flash Cookie)

Initial Tags
object, flash

Initial Language
ActionScript 3