简体   繁体   中英

Flash cookie (Local Shared Object) - creates wrong paths through browsers

I wrote a little AS3 code to test Flash cookies. When I publish it in the Adobe Flash Professional CS6, it works - writes, reads as it should, and in %APPDATA% shared objects folder it writes folders/file correctly: localhost/.../app3.sol . But when I run the .swf through an html page on a local server, the browser (firefox, chrome) doesn't read/write the LSO correctly, instead of "localhost" folder, it creates a "#localhost" and at the end of the path no .sol file is generated. So basically - LSO works if swf is opened localy, but doesn't when opened from server.

This is my piece of code:

//gets LSO object / creates if it doesn't exist
var mySharedObject:SharedObject = SharedObject.getLocal("app3");

//output string from LSO to a text field
viewer.text = mySharedObject.data.viewer;

//when button clicked, get textfields current text and save it in LSO
lso_save.addEventListener(MouseEvent.CLICK, saveLso);

function saveLso(e:Event):void
{
    mySharedObject.data.viewer = viewer.text;
    mySharedObject.flush();
}

Any ideas?

You can try to set a path "/" to the SharedObject:

var mySharedObject:SharedObject = SharedObject.getLocal("app3", "/", false)

More info: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html#getLocal()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM