Newest Articles

MegaCombs
Flash Media Player
XML Driven Pie Chart
Base Defender
Hangman Game
8 Ball Pool


Popular Articles

True Fullscreen Flash Mode
Mp3 Player with XML Playlist
Hangman Game
Create Pong
3d Rotating Image Cube
Catapult Game


Random Articles

Photo Reel
Custom Mouse Cursor
Growing Tree using Recursion
Spark Effect
Mouse Following Preloader
XHTML Image Mapper


Links

Shapes the Game
Reddit
Newgrounds
TWiT
Link to SwfSpot
Swf Spot

Contact me on Google+



rss feed

Storing Data Similar to Cookies

Storing Data Similar to Cookies
AddThis Social Bookmark Button
Description: Store data with flash so that data remains after closing an applet.
Author: John Bezanis
Added: March 29th 2007
Version: Flash 8


Flash uses Shared Objects to allow data to be stored even after a user closes a flash applet. This is very similar to a browser's use of cookies. Main code in the applet:
  1. //Select the local shared object
  2. var so:SharedObject = SharedObject.getLocal("setbgcolor");
  3. //check if the bgcolor has been previously set
  4. if(so.data.bgcolor!=undefined){
  5.   //if set, set the background color to that color
  6.   setcolor(so.data.bgcolor);
  7. }
  8. //set the background color and save it.
  9. function setcolor(color){
  10.   var bgcolor = new Color(bg);
  11.   bgcolor.setRGB(color);
  12.   so.data.bgcolor=color;
  13.   //force the file to be written
  14.   so.flush();
  15. }
Each button in the applet calls the following code in the on(press) function: setcolor(0x00FF00); 0x00FF00 is a hexadecimal number, and you can tell that because hexadecimal numbers begin with 0x in flash. To delete a set variable in this applet use either delete so.data.bgcolor; or so.clear();

Download Source File
Comments Currently Disabled