How do I use cookies or other local storage in Flash?

1

I would like to persist some information in the program I'm doing in Flash.

I need to save primitive data from my application's inner controls, and I thought of something like a local XML or a cookie .

Is it possible to do something like Flash? How?

    
asked by anonymous 19.05.2014 / 22:20

2 answers

5

ActionScript (Flash) works with a class called SharedObject , which is not necessarily LocalStorage (which is an HTML5 object). You can use both local cookies and a Media Server and even even displaying streams like sounds and videos.

This class creates a file known as SOL File , located only in the "% appData% / Macromedia / Flash Player / # SharedObjects / _pasta_com_id_ / ", containing values of Boolean, String, Number, int, and Array variables.

To use this method, follow the code below:

var so:SharedObject = SharedObject.getLocal("NomeDoArquivoSol");
so.data.nome = "SeuNome";
so.data.numero = 20;

var nome:String = so.data.nome;
var numero:int = so.data.numero;

trace(so.data.nome); //SeuNome
trace(so.data.numero); //20
trace(nome); //SeuNome
trace(numero); //20

Soon after this file is created it can be accessed at any time, even if you close the swf and open it again, the values will still be there.

Be careful when creating this type of file for passwords, encryptions, and the like. With the wrong configuration you may be exposing all your code.

    
19.05.2014 / 23:00
5

You must first create your object

var myObj:SharedObject = SharedObject.getLocal("cookie");

Then assign the data

myObj.data.firstName = "John";
myObj.data.lastName = "Doe";

And finally save the data

myObj.flush();
  

The getLocal method in addition to creating a new instance, recovers if there is already a

obs: the response information is derived from the article Using AS3 SharedObject in Flash that has more useful information about it.

    
19.05.2014 / 22:29