现在的位置: 首页 > 综合 > 正文

共享对象技术细节

2014年02月07日 ⁄ 综合 ⁄ 共 1951字 ⁄ 字号 评论关闭
【1】给共享对象赋值的正确的方法应该是:
1 : client1 = "a";
2 : client2 = "b";
3 :
4 : temp = new Object();
5 : temp[client1] = client1;
6 : temp[client2] = client2;
7 :
8 : client_so.data.users = temp;
【2】若要删除本地共享对象的属性,请使用诸如 delete so.data.attributeName;将本地共享对象的属性设置为 null 或 undefined 不会删除该属性,只是初始化该值。
删除共享对象:删除所有data子项,然后删除sharedobject;
mySO = SharedObject.getLocal("test");
mySO.data.stickAround = "I'll be here for years to come!";
mySO.data.myArray = new Array(1, 2, 3, 4);
mySO.flush();
delete mySO;
// Reload the SO
mySO = SharedObject.getLocal("test");
for (a in mySO.data) {
delete mySO.data[a];
}
mySO.flush();
// Delete the SO
delete mySO;
 
sharedobject.clear();for local shared objects, purges all of the data and deletes the shared object from the disk. The reference to my_so is still active, but my_so data properties are deleted.

For remote shared objects, this method disconnects the object and purges all of the data; if the shared object is locally persistent, the method also deletes the shared object from the disk. The reference to my_so is still active, but my_so data properties are deleted.

【3】

so.data.itemNumbers = itemsArray;
so.data.adminPrivileges = currentUserIsAdmin;
so.data.userName = currentUserName;
上面的形式可以写为
so.data['itemNumbers'] = itemsArray;
so.data['adminPrivileges'] = currentUserIsAdmin;
so.data['userName'] = currentUserName;
是等效的。
【4】
若要创建共享对象的“私有”值(该对象正在使用时只有客户端实例才可以使用并且当对象关闭时不与该对象存储在一起的值),请创建名称不为 data 的属性来存储它们,如下面的示例
所示。

so.favoriteColor = "blue";
so.favoriteNightClub = "The Bluenote Tavern";
so.favoriteSong = "My World is Blue";
【5】
建立远程共享对象的方法:
var client_nc = new NetConnection();
client_nc.connect("rtmp://localhost/videochat/room1");
so = SharedObject.getRemote("records",client_nc.url);//数据资料不写入磁盘
so.connect(client_nc);
 
so = SharedObject.getRemote("records",client_nc.url,true);
//数据资料写入服务器端应用程序文件夹
//该语句远程共享的文件名将是records.fso
【6】
1 : so.data.user = { id:1,sex:b,name:liu21st }
2 : // 在存取的时候可以使用
3 : // so.data.user.name的方式
对共享对象的data属性赋NULL或undefined可以初始化字段
so.data.userID = NULL ;
但是并没有删除该字段,如果要删除请用:
delete so.data.userID;
我们也可以使用类似于
so.data.year.month.dayOfMonth = someValue;的方式来赋值
//注意该赋值并非一个字段 year.month.dayOfMonth
//而分别是给三个字段 year,month,dayOfMonth 初始化相同的值
 

抱歉!评论已关闭.