案例:点击变大变小的按钮改变当前状态,同步到服务器上。(服务器端改变用户属性)
客户端的代码
#VRML V2.0 utf8
DEF allplay Transform {
translation 0 0 0
children [
]
}
DEF myBoxUI GUIGroup {
imagesets ["datas/imagesets/IPhone.imageset"]
lookfeels ["datas/looknfeel/IPhone.looknfeel"]
schemes ["datas/schemes/IPhone.scheme"]
children [
DEF turnBig GUIWindow {
type "IPhone/Button"
size 0.1 0.1
position 0.8 0.8
text "turn big"
}
DEF turnSmall GUIWindow {
type "IPhone/Button"
size 0.1 0.1
position 0.65 0.8
text "turn small"
}
]
}
DEF system System {}
DEF script_easyServer Script {
eventIn SFBool click_turnBig
eventIn SFBool click_turnSmall
field SFNode tempSFNode NULL #存入节点的变量
field SFNode allplay USE allplay
field SFString Bname "" #存放用户名信息
field SFString Bsize "test_mybox_Tbox_Bsize" #存放用户大小信息
field SFString Btran "test_mybox_Tbox_Btran" #存放用户坐标信息
field SFString Bchange "test_mybox_Tbox_Bchange" #存放用户改变的状态
url "javascript:
//点击后用户大小信息改变
function click_turnBig(v){
var usertemp = SFNode.get('userinfo');
usertemp[Bchange]='big';
}
function click_turnSmall(v){
var usertemp = SFNode.get('userinfo');
usertemp[Bchange]='small';
}
//用户信息同步信息时自动调用
function lyinuxUserSync(user,fields,timeouts){
//拿到已经改变的信息
alert('Box{ }===>'+SFNode.get(user['test_mybox_Tbox_Bname']+2));
alert(user['test_mybox_Tbox_Bname']);
//得到需要改变的信息
var chengebox = SFNode.get(user['test_mybox_Tbox_Bname']+2);
chengebox.size[0] = user[Bsize][0];
chengebox.size[1] = user[Bsize][0];
chengebox.size[2] = user[Bsize][0];
alert('改变盒子的大小'+chengebox.size);
}
//用户进入空间时调用
function lyinuxEnterSpace(user,space,others){
alert(user.getName());
alert('user[test_mybox_Tbox_Bname] == '+user['test_mybox_Tbox_Bname']);
Bname = user['test_mybox_Tbox_Bname'];
alert('Bname===='+Bname)
alert('others======'+others[0]);