Setting and retrieving cookies from Flash using Javascrip
find the Set Cookies functions as below:
function GetCookie(cookieName) { js = "javascript:function gc(){"; js += "var s = '" + cookieName + "=';"; js += "var r = 'false';"; js += "var c = document.cookie;"; js += "if (c.length > 0) {"; js += "o = c.indexOf(s);"; js += "if (o != -1) {"; js += "o += s.length;"; js += "e = c.indexOf(';', o);"; js += "if (e == -1) e = c.length;"; js += "r = unescape(c.substring(o, e));"; js += "}"; js += "}"; js += "var f = document.getElementById('flashLoader');"; js += "if(f) {"; js += "f.SetVariable('cookieVariable', r);"; js += "}"; js += "}gc();"; getURL(js); return cookieVariable; } function SetCookie(cookieName, cookieValue) { js = "javascript:function sc(){"; js += "var c = escape('" + cookieName + "') + '=' + escape('" + cookieValue + "') + '; path=/';"; js += "document.cookie = c;"; js += "}sc();"; getURL(js); }
and for the Get Cookies function read as follows:
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; }
source from http://www.actionscript.org and for more information,
http://www.actionscript.org/forums/showthread.php3?t=63951
Leave a Comment