?? main.asc
字號:
load("components.asc")
application.onAppStart = function(){
//Array of connected users
this.userList = new Array();
//Object to hold a direct reference to connected clients
this.userHandler = new Object();
//Shared Object to store connected users
this.users_so = SharedObject.get("users", false);
this.users_so.setProperty("userList", this.userList);
}
application.onConnect = function(client, name) {
//Check if the user exists
for(i=0; i<this.userList.length; i++){
if(this.userList[i]==name){
application.rejectConnection(client);
return;
}
}
//register user to framework
gFrameworkFC.getClientGlobals(client).username = name;
// Store a reference to this user
this.userHandler[name] = client;
// Add this user to the userList array
this.userList.push(name);
//saves array of connected users to the Shared Object
this.users_so.setProperty("users", this.userList);
// Accept the new client's connection
this.acceptConnection(client, name);
}
application.onConnectAccept = function(client, name){
//Sets username in client side
client.call("setUser", null, name);
//Broadcast the event to all connected users
this.users_so.send("newUser", name);
}
application.onDisconnect = function(oldClient){
//Get username from framework
var username = gFrameworkFC.getClientGlobals(oldClient).username
//Broadcast disconnection
this.users_so.send("onDisconnect", username, true);
//Deletes user reference
delete this.userHandler[username]
//Deletes user from the users array and the SO
for(i=0; i<this.userList.length; i++) {
if(this.userList[i] == username) {
this.userList.splice(i, 1)
this.users_so.setProperty("userList", this.userList);
}
}
}
//Returns number of connected users
Client.prototype.checkClients = function(){
return application.userList.length
}
//Route an invitation from source to guest
Client.prototype.invite= function(source, guest){
application.userHandler[guest].call("showMessage", null, source)
}
//Route an answer to an invitation with three posible states: true, false or "busy"
Client.prototype.joinRoom = function(source, guest, flag){
application.userHandler[source].call("openRoom", null, flag, guest+"_"+source, guest)
application.userHandler[guest].call("openRoom", null, flag, guest+"_"+source, source)
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -