4

How can I make cookies in my Flash application using ActionScript 2.0?

grapefrukt
  • 27,016
  • 6
  • 49
  • 73

4 Answers4

3

You would need to use JavaScript to work with cookies. You can do so from ActionScript using the ExternalInterface API.

Andrew Van Slaars
  • 1,816
  • 1
  • 14
  • 20
3

If you just need local storage and don't have a specific need for cookies Flash has it's own flavour of cookies called SharedObjects. They work more or less the same but they're only readable from Flash, they will however save you the bother of interfacing with javascript.

grapefrukt
  • 27,016
  • 6
  • 49
  • 73
  • Yes for most uses this is the best way to go - they even work cross-browser I think. – Iain Nov 13 '08 at 09:07
0

In AS2, I would say just create a javascript function to set the cookie and call it from within flash using a geturl request.

// Javascript Function
function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

// AS2 Function
myBtn_btn.onRelease = function(){
 getURL("javascript:setCookie('my_cookie','my_value','30')");
};

Hope that helps. chews

p.s. that is untested code but it should work :-)

chews
  • 2,579
  • 2
  • 20
  • 10
0

Flash ActionScript as own Cookies Mechanism which called Local Shared Object. you can use Local Shared Object as a cookies and when you will load once again same application you will find out the same data which stored in previous loaded application session.

Mrugesh
  • 461
  • 4
  • 16