Archivo

Archivo para Octubre, 2007

Cookies desde Flash

Domingo, 21 de Octubre de 2007

Buscando en la internet me encontré este muy interesante código para manejar cookies usando javascript desde actionscript:
Foro en Actionscript.org.

Código Actionscript:

import flash.external.ExternalInterface;
function GetCookie(cookieName) {
var r = "";
var search = cookieName+"=";
var js = "function get_cookie(){return document.cookie;}";
var cookieVariable = ExternalInterface.call(js).toString();
if (cookieVariable.length>0) {
offset = cookieVariable.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookieVariable.indexOf(";", offset);
if (end == -1) {
end = cookieVariable.length;
}
r = unescape(cookieVariable.substring(offset, end));
}
}
return r;
}
function SetCookie(cookieName, cookieValue) {
js = "javascript:function sc(){";
js += "var c = escape('" + cookieName + "') + '=' + escape('" + cookieValue + "') + '; path=/';";
js += "document.cookie = c;";
js += "}sc();";
getURL(js);
}

Actionscript, Programar, Web