views:

1698

answers:

3

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

+2  A: 

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

Andrew Van Slaars
A: 

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
+3  A: 

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
Yes for most uses this is the best way to go - they even work cross-browser I think.
Iain