Newest Articles

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


Popular Articles

True Fullscreen Flash Mode
Image Slider
Mp3 Player with XML Playlist
FLV Player
Catapult Game
3d Rotating Image Cube


Random Articles

Glowing Orb
Combs
Album Slide
Horizontal Line Transition
Bouncing Ball with Smoke Effect
onEnterFrame vs setInterval


Links

Foundation-Flash
MickM
TutorialQuest
Tutorialsphere.com - Free Online Tutorials
Newgrounds
TWiT
Link to SwfSpot
Swf Spot



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
Hello,

I have turn on/off music button on my web site. How can I store data if music is on or off. Thank u in advance.
April 18th 2007 05:04AM   -   Stefan
Hey Stefan,
You could use an if statement to see if the music has been set to on or off, or if it is not set.
April 19th 2007 01:04AM   -   John
Hello,How can I store data in flash
September 6th 2007 02:09PM   -   jp
hi, ay i want to make it so when the player gets up to a certain question in mi quiz, when they close it then re open it, its exactly where they left it, any suggestions on the code to do that??
January 21st 2008 03:01AM   -   pioallergenic
Hi,

Can u tell me how to change shared object pathe from "C:\Documents and Settings\Harish\Application Data\Macromedia\Flash Player\#SharedObjects\D8F43EBD\localhost\Sample\Sample.swf" to My "D:\Sample" folder. u can send solution to harish_neermarga@rediffmail.com

Plse help..

Thank you
June 13th 2008 01:06AM   -   Harish
How do you make a object create from another object, and make a enemy that disappears after hit by another object?
June 14th 2008 12:06PM   -   Dragonblue80
hello how to store the data obtained through the flash .....
as in the case of a data obtained through a questionnaire?
please send to drthomassebastian@rediffmail.com
December 8th 2008 08:12PM   -   thomas
Add a Comment
name:
website (optional):
captcha type the characters into the box
message (5000 characters or less):