SHARE
Facebook X Pinterest WhatsApp

Flash Tutorial for Web Developers: Save/Load Info Using Cookies

Apr 7, 2010

Have you ever made a huge Flash game and knew that there was no way a person could beat it in one day? Well, now you can save and load information via cookies so the game can resume when they’re ready with this tutorial from the FlashKit community!


To start with, the files that are generated are .sol files, and that data is saved as block text so there is no way someone can alter it to changen their score, etc. I’m going to show you how to use cookies to do this using ActionScript.


Start up Flash and create a button–for our example this will be the “Save” button. Put this in its ActionScript panel like so:

on (release)
{
_root.pos = sharedobject.getLocal(“COOKIE NAME”);
_root.pos.data.guy = _root.guy._x;
_root.pos.data.guy = _root.guy._y;
_root.pos.data.NAME = _root.NAME;
}

Ok, let

s take this step by step


_root.pos = sharedobject.getLocal(“COOKIE NAME”);

This means that you have just created

pos

, which is the cookie file itself. For

COOKIE NAME

, name it whatever you want, but make sure that it is appropriate for the type of save for easy remembering, i.e.:

player 1 save

or something like that.


_root.pos.data.guyx = _root.guy._x;
_root.pos.data.guyy = _root.guy._y;
_root.pos.data.NAME = _root.NAME;

This is basically what it

s saving. It records the MC

guy

s _x and _y positions into pos

data. Of course, you don

t have to name them guyx and guyy, you can name them anything, but don

t change _root.guy._x and _y, because those are the actual targets. NAME is the instance name for items such as a dynamic text box for saving the score, or anything like that.



Now for the load button–create one and put this in the ActionScript panel:

on (release) {
_root.pos = sharedobject.getLocal(“COOKIE NAME”);
setProperty(_root.guy, _x, _root.pos.data.guyx);
setProperty(_root.guy, _y, _root.pos.data.guyy);
_root.NAME = _root.pos.data.NAME;
}

This sets the properties for the things that are saved from the stage. For those that aren

t, you must use the attachMovieClip() function and then set its properties.



That’s it! Now you can create games which hold the scores, user information, position in the game, etc. Now start making some games!

Recommended for you...

Shopify Alternatives
Helpful Tips for Designing a Landing Page that Converts
Five Essential HTML5 Editors
Best Web Hosting Providers
Enrique Corrales
May 31, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.