How to use cookies or other local storage in Flash?

Asked

Viewed 267 times

1

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

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

Is it possible to do something like this in Flash? How?

  • 1

    Why did they give me -1?

  • 2

    Probably because initial ignorance is easily solved by Google. The subsequent is the interesting: "Cookie in Flash gives mefistofoles dick". Anyway, it seems to me, I didn’t vote or + nor -. Oh, yeah, if I remember correctly, the Flash works with Localstorage.

  • @Brasofilo, regarding his "why the initial ignorance is easily solved by Google", did not find an answer that meets my need. If you so well-known, why don’t you help me?

  • 2

    @brasofilo I believe that even questions of this type are important for the site we will assume that a flash beginner type the above title in Google which by the way is very consistent to doubt, he will find easy this page, so I don’t think we should have this attitude towards the person who asked! and vote to delete all such comments as soon as possible

  • 1

    Wow, didn’t I give you a password to research? I, huh, then there’s that cry "It has to be mandatory to explain the downvote", someone explains and still takes whack... Out on the left, I went..!

  • Which one? "metisfofoles" and "Localstorage".

  • 4

    This type of question, which asks how to do something without showing one’s own attempt, is somewhat controversial (participate in the discussion which we have already had on the subject). Otherwise, the question was extremely misspelled, and no form of question had. I believe that this may have led to at least part of the opposing votes. I edited to fix it and I’m voting to reopen; now it’s in the hands of the community.

Show 2 more comments

2 answers

5

You need to 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 method getLocal in addition to creating a new instance, recovers if there is already a

Obs: the response information derives from the article Using AS3 Sharedobject in Flash who has further useful information on.

5


Actionscript (Flash) works with a class called Sharedobject, which is not necessarily Localstorage (which is an HTML5 object). You can use either local "cookies" or in a Media server and even view streams like sounds and videos.

This class creates a file known as SOL ARCHIVE (Shared Object Local, . sun), located only in the folder "%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 continue there.

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

  • Thanks @biio, helped me a lot.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.