Flex通过javascript读写cookie
当flex需要在客户端写入/读取一些状态信息的时候,我们会想到用cookie。flex是不支持cookie的,只有SharedObject这个本地对象。所以解决的办法就有两个:
flex通过调用js来实现对cookie的操作;
js通过flex实现对SharedObject的操作;
这两种方法的基础就是实现flex和javascript的交互,自己试着写了个小例子,实现了第一种方法,直接上代码:
Flex_Js_Cookie.js:
view plaincopy to clipboardprint?
function SetCookie(name,value)
{
document.cookie = name+"="+escape(value);
};
function GetCookie(name)
{
var arr = document.cookie.match(new RegExp("(^|)"+name+"=([^;]*)(;|$)"));
alert(arr.length);
if(arr != null)
{
return unescape(arr[2]);
}
}
function SetCookie(name,value)
{
document.cookie = name+"="+escape(value);
};
function GetCookie(name)
{
var arr = document.cookie.match(new RegExp("(^|)"+name+"=([^;]*)(;|$)"));
alert(arr.length);
if(arr != null)
{
return unescape(arr[2]);
}
}
Flex_Js_Cookie.html:
view plaincopy to clipboardprint?
var flashvars = {};
var params = {
menu: "false",
scale: "noScale",
allowFullscreen: "true",
allowScriptAccess: "always",
bgcolor: "#FFFFFF"
};
var attributes = {id:"swfplayer"};
swfobject.embedSWF("Flex_Js_Cookie.swf", "swfplayer", "500", "350", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
var flashvars = {};
var params = {
menu: "false",
scale: "noScale",
allowFullscreen: "true",
allowScriptAccess: "always",
bgcolor: "#FFFFFF"
};
var attributes = {id:"swfplayer"};
swfobject.embedSWF("Flex_Js_Cookie.swf", "swfplayer", "500", "350", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
Flex_Js_Cookie.mxml:
view plaincopy to clipboardprint?
layout="absolute">
layout="absolute">
通过代码,会发现在html文件里面使用了swfobject.js这个文件,这是一个第三方发布的工具包,方便我们在页面中使用flash,下载地址是:http://code.google.com/p/swfobject/downloads/list。只要里面的js文件。
mxml文件要预先编译成swf文件。然后一起部署到tomcat下就可以运行了。
猜你喜欢
转载自qr728qr.iteye.com/blog/1574460
今日推荐
周排行