Saving data on your local computer

AS3 provides a class, SharedObject, to let us save a limited amount of data on our local computer. The class does not create cookies, but something very similar called LocalSharedObjects, and the concept is the same.

It's very important to understand that LocalSharedObjects maintain local persistence. This means that you can play the game, make an high score, turn off your computer, and next time you'll play the game on the same computer, it will retrieve the high score.

Exactly what we need. Let's see how to use it. First, we need to import the SharedObject class:

import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.filters.GlowFilter; import flash.net.SharedObject; ...

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.