📜 ⬆️ ⬇️

Local Shared Objects - Flash Cookies

Entry

Greetings residents Habra!
Often there are cases where we are obliged to save data that the user works on in Flash (game points, workspace decorations, etc.).
Many people think that you need to create a bridge between PHP and Flash. In some cases, this needs to be done in order to store data about certain user actions for a long time on the network. But sometimes it is required on the client side to save data that is intended only to determine which function the user has selected and, depending on this, provide him with the necessary information. Today we will consider saving data on a computer, namely Local Shared Object (hereinafter referred to as LSO), that flash cookies are sometimes popular among people.

Lso

Little about technology

Local Shared Objects - commonly called a Flash cookie, is a type of data stored as a file on a user's computer. All Flash Player versions are currently using LSO.
Usually with the default settings, Flash asks the user for permission to store local files on the computer. I am sure many have seen it, so some of the readers already understand what I am writing here. As with regular cookies, online banks, advertisers or merchants can use the LSO for accounting and control purposes. Flash cookies cannot be used by third parties on other sites. For example, LSOs from the site “www.site.ru” cannot be read by the site “www.site.com”.
If the user gets rid of the site’s cookie, a unique ID cookie will be assigned to the new file using Flash data as a “backup”.
A user can opt out of storing an LSO using the global storage settings in the Setting Manager on the official Adobe website.

Setting manager
')
LSO storage on computer

The default locations for LSO files usually depend on the operating system. LSOs ​​are stored on a computer under the “.SOL” format.

Windows 7:
AppData / Roaming / Macromedia / # SharedObjects /

Linux:
~ / .macromedia / Flash_player /

Mac OS X:
~ / Library / Preferences / Macromedia / Flash Player / # SharedObjects

From theory to practice

I have prepared a small example in ActionScript3 so that you can see how to work with the LSO in “real conditions”.
My example is a scene on which are located:

Buttons serve us in order to clear and enter data into variables, as well as save them in a cookie.
The input field is used to enable the user to enter data that he wants to put in a variable, and use the color picker to select the background color of our scene.

import fl. events . ColorPickerEvent ;
import flash. geom . ColorTransform ;
import flash. events . MouseEvent ;

var Save: SharedObject ;
Save = SharedObject . getLocal ( "application-name" ) ;

label. text = "String: '" + Save. data . save1 + "'" ;
pal. selectedColor = Save. data . save2 ;

var color : ColorTransform = fon. transform . colorTransform ;


fon. addEventListener ( ColorPickerEvent. CHANGE , col ) ;
butt. addEventListener ( MouseEvent. CLICK , ok ) ;
butt1. addEventListener ( MouseEvent. CLICK , ex ) ;


function ok ( e : MouseEvent ) : void
{
Save. data . save1 = "You are back" + texts. text ;
label. text = “Hello” + texts. text ;
}

function ex ( e : MouseEvent ) : void
{
delete save. data . save1 ;
label. text = "Exit" ;
}

function col ( e : ColorPickerEvent ) : void
{
Save. data . save2 = color . color = pal. selectedColor ;
fon. transform . colorTransform = color ;
}


Palitra

Conclusion

So we came to the end of our experiment and now we can safely say that we should not be afraid of such a thing as Local Shared Objects.
After the work done, I immediately went to the folder where the cookie is stored. I found my own localhost in the daddy, and in it the file application-name.sol .
Opening it saw the following:
ї QTCSO application-name save2Ѓ save1='‹ ІµЂЅѓ»ЃЊ Ruslan

Comment by Emin
It is highly desirable to use the flush () method to force save. To avoid problems when accessing data.

Up to 100 KB Flash does not request storage permission. If more than 100 KB, then the query appears.

Thank you all for reading my article!

Source: https://habr.com/ru/post/111176/


All Articles