/ Published in: ActionScript 3
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
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//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;