一,什么是共享对象?它的英文名称为SharedObject(以下简称SO)。在flash MX里,SO允许你在使用者本机上存储所有flash支持的数据(包括:Array, Boolean, Date, Number, Object, String, XML...etc),如同在浏览器中使用cookie一样。SO的存储位置,一是本地客户端的硬盘;二是存放在服务器上。在这里,我只能简单介绍一下本地共享对象(Local shared object)的使用。本地共享对象存储默认存储路径为:C:\DocumentsandSettings\登录名称\ApplicationData\Macromedia\FlashPlayer\服务器网域名称\影片路径\影片文件名.swf\...其扩展名为*.sol。默认情况下,Flash 可以在本地保存多达 100K 大小的永久性远程共享对象。当您尝试保存一个较大的对象时,Flash Player 将显示“本地存储”对话框,用户可以使用该对话框允许或拒绝请求访问的域的本地存储。如果用户选择“从不”,那么SO将无法完成保存任务。SO的名称可以包含正斜杠 (/);例如 work/addresses 就是合法名称。SO名称中不允许使用空格,也不允许使用以下字符: ~ % & \ ; : " ' , < > ? # ;SO存储的信息具有只读属性,你每次打开swf播放器的时候,会获得该信息。
测试代码:
//创建一个名为kookie的本地共享对象;
this.so = SharedObject.getLocal("kookie");
//给共享对象添加一个username的属性来记住使用者;
this.so.data.username="bluelife";
//添加该属性不会将它保存到硬盘。只有影片被卸载或使用语句so.flush()强制保存信息。
this.so.flush();
//现在可以用trace语句获取一下username的值;
trace(this.so.data.username);
//添加下面这个语句,再trace一下,username值为空。注意该命令只清除硬盘信息,SO对象仍然存在,可以引用.
this.so.clear();
SO对象的其它方法的使用,请查阅flash帮助文档,这里不再赘述。
二,共享对象的应用.如果理解SO对象可以永久保存用户的数据的话,那么它可以用来记录flash游戏的成绩,使用者的个人信息(姓名,年龄,爱好...ETC)
两个独立的swf文件,如果存放在同一文件夹下,可以共享一个名为“cookies”的SO。方式是:
anotherSO=SharedObject.getLocal("shared","/");
同理,在子目录下的SO对象,可以这样共享。
anotherSO=SharedObject.getLocal("shared","/test1/");
anotherSO=SharedObject.getLocal("shared","/test1/test2/");
应用一:
-----------------------------
//copy right :edmack.com 可读写的Cookie
MovieClip.prototype.setCookie = function (c,n,v){
var so = SharedObject.getLocal(c);
so.data[n] = v;
so.flush();
};
MovieClip.prototype.getCookie = function (c,n){
var so = SharedObject.getLocal(c);
return so.data[n];
};
//c = cookie name
n = 存储的变量名称
v = 要存储的变量值
--------------------------------
应用二:
--------------------------------
//by Steve Grosvenor 记录本地用户的访问次数
sObjVisits = SharedObject.getLocal("userVisitsLocal");
if (sObjVisits.data.visits == undefined) {
sObjVisits.data.visits = 1;
} else {
sObjVisits.data.visits = sObjVisits.data.visits+1;
}
howManyVisits = sObjVisits.data.visits;
sObjVisits.flush();
visits.text = "been here "+howManyVisits+" times";
---------------------------------
应用三:
--------------------------------
//本地使用者的帐户登陆,上传我做的一个练习。
so=SharedObject.getLocal("userinfo");
function checkin(){
if(this.mytxt.text==so.data.user&this.psword.text==so.data.psword){
this.gotoAndStop(2);
this.msg.text="you are come back again!";
}
else if(this.mytxt.text!=so.data.user){
so.data.user=this.mytxt.text;
so.data.psword=this.psword.text;
so.flush();
this.gotoAndStop("welcome");
this.msg.text="you are new visitor.";
}
else trace("error");
}
checkbtn.onRelease=function(){
checkin();
}
this.mytxt.text=so.data.user;
this.psword.text=so.data.psword;
stop();
--------------------------------
应用四:
--------------------------------
//by mvmartin 保护swf文件的手段
//“尽管如同星光所说,任何的保护都是徒劳的,但...那是另一回事了”.
这种保护手段是以用户的使用时间为界限的。当我们设定时间线,用户在第二次使用的时候,会得到期限已过的警告。我知道这是一个陈旧的简单的保护手段,用户可以修改系统时间来绕过“障碍”。为了避免这样的情况,SO对象就派上用场了. 保护代码持续跟踪swf文件上次使用的时间。假定用户更改电脑的系统时间回到早先,那么我们仍然可以通过SO知道这个欺骗手段。也就是保证用户以后访问的时间必须大于上次访问的时间,那么我们给定的时间限制就真正起作用了。下面给出代码,如果你喜欢,可以做测试。给定一个你期望的限制时间段,然后设置系统时间超前,那么swf会跳转到你所指定的STOP帧;如果把系统时间返回到“先前”,你仍然会得到相同的结果。//
1) 主时间轴上建立一个实例名为 DateCheck的影片剪辑MC (里面是空的,只包含代码).
2) 在影片剪辑DateCheck的第一帧:
// 这部分代码检测用户是否将系统时间人为的“提前”。
// 建立一个名为datesharedobject.sol的共享对象.
D4XSO.data.datelastaccessed = new Date();
D4XSO = sharedobject.getLocal("datesharedobject");
// 设定 "now" 等于当前系统时间
var now = new Date();
if (now< D4XSO.data.datelastaccessed) {
// If the computer date (now) is less than the date last accessed,
// then the date has probably been set backwards on the users computer,
// so set "now" forward to that last accessed date so they can't
// access the course.
var now = D4XSO.data.datelastaccessed;
trace("Today's date (now) is being set to the datesharedobject date, which means the computer was set back; =");
trace (D4XSO.data.datelastaccessed);
trace ("Which should equal what now has been set to, which is:");
trace (now);
// Else if the computer date (now) is greater than the last date accessed,
// then all is right with the world, so go ahead and write that date
// back to the shared object as the date last accessed.
} else {
D4XSO.data.datelastaccessed = now;
D4XSO.flush();
trace("The datesharedobject date is being updated to today's date =");
trace(D4XSO.data.datelastaccessed);
}
3) 稍微给一点延迟时间,比方在第20帧的代码如下.
var start = new Date(2003, 10, 1);
// set start equal to 11/1/2003 (Jan = 0)
var end = new Date(2004, 6, 15);
// set end equal to 7/15/04; do not put zeros in front of numbers
if (now // if date is before start, then they're trying to cheat us, so give error message
trace ("If you're seeing this then the now is before the START date, meaning they've set the clock back too far.");
trace ("The START date is:");
trace (start);
trace ("Today's date (now) is set at:");
trace (now);
_root.gotoAndStop(31);
} else if (now>end) {
// if date is after end, then go to end
trace ("If you're seeing this then the now is before the END date");
trace ("The END date is:");
trace (end);
trace ("Today's date (now) is set at:");
trace (now);
_root.gotoAndStop(31);
} else {
trace ("Everything is hunky-dorey, let's go!");
play();
}
stop();
来源:http://qzone.qq.com/blog/14339015-1203305457
http://blog.sina.com.cn/s/blog_494f8065010004aw.html
分享到:
相关推荐
有时候会碰到cuda报错,OSError: libcudart.so.10.0: cannot open shared object file: No such file 原因是cuda动态链接库没有链接上。 解决方法如下: cuda10.0: sudo ldconfig /usr/local/cuda-10.0/lib64 cuda...
#资源达人分享计划#
自己动态库映射地址不一样
AS3 SharedObject 本地通讯 小例子!以前很久的时候参考网上例子学习的!刚接触本地通讯的童鞋可以试试。
SOLReader is a decompiler for the .sol files used by flash to save its own cookie (the SharedObjects)
shared Object对象相当强大,他提供了在多个客户端实时数据共享,并且可以存储在客户端或远程服务器。可以把本地共享对象比作cookies,把远程共享对象看作实时的数据传输设备。
OSError: libcusparse.so.11: cannot open shared object file: No such file or directory 搜索全网,也没找到解决方案。最快解决方案如下: 1、在 /home/user/anaconda3/lib/ 中放入缺少的 libcusparse.so.11 文件...
ubuntu报错:libg2c.so.0:cannot open shared object file: no such file or directory/wrong ELF class(已解决)-附件资源
用于单机游戏中的 进度保存。 SharedObject 望有帮助
libXp.so.6: cannot open shared object file: No such file or directory [oracle@dbadb1 ~]$ ls -ld /usr/lib/libXp.so.6 ls: /usr/lib/libXp.so.6: No such file or directory [root@dbadb1 zhuxu]# rpm -ivh...
针对以下帖子的实验(Linux版): http://topic.csdn.net/u/20100317/09/1cb8411a-74a9-4f05-ae5e-1e068b06654c.html
本编辑器是我自己做的,最初是因为玩一个flash做的游戏(金庸群侠传2),感觉升级太慢,想到要修改其保存的属性值,之后就有了此作。原文件和详细说明都打包在里面! 解压密码:scriptfan@qq.com
error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory [root@SnsWeb ~]# /usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --log...
tensorflow.python.framework.errors_impl.NotFoundError: libnccl.so.2: cannot open shared object file: No such file or directory。 根据报错的内容,我们知道,缺少一个文件,libnccl*** 类似的东西,看到nccl...
cannot load library 'libcairo.so.2': libcairo.so.2: cannot open shared object file: No such file or directory cannot load library 'libcairo.2.dylib': libcairo.2.dylib: cannot open shared object file: ...
android-sdk-NDK18.1.5063045.rar
MYSQL之 error while loading shared libraries: libtinfo.so.5: cannot open shared objectfile: No such f-附件资源
如何使用 ngSharedObject得到它您可以使用 bower 来获取模块: $ bower install ng-shared-object --save配置角度将ngSharedObject添加到您的模块中: angular . module ( 'modulename' , [ 'ngSharedObject' ,] )...