21
Oct 07

Cookies desde Flash

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);
}


Leave a Reply


Copyright © 2016 Silenceway
Proudly powered by WordPress, Free WordPress Themes

 Subscribe in a reader