And now, without further ado, here is the list of all events and functions that the ElectroServerAS object can perform.
ElectroServerAS.addToHistoryUsage: ElectroServerAS.addToHistory(message)
Returns: Nothing. Description: Method; appends a string to the history property, ElectroServerAS.history. Example: The following line adds a chat message to the history property: ElectroServerAS.addToHistory("Anyone for a game of golf?") ElectroServerAS.banUsage: ElectroServerAS.ban(who, why)
Returns: Nothing. Description: Method; disconnects a user from the ElectroServer socket server and bans him or her from connecting from that IP address again. This method is only available to users with administrator-level access. See also ElectroServerAS.login. Example: The following line bans a user: ElectroServerAS.ban("meanie", "Offensive language") ElectroServerAS.cancelChallengeUsage: ElectroServerAS.cancelChallenge() Parameters: None. Returns: Nothing. Description: Method; cancels the challenge request you sent out. The ElectroServerAS.challengeCancelled event is fired on the challengee's side. ElectroServerAS.challengeUsage: ElectroServerAS.challenge(who, game)
Returns: Nothing. Description: Method; challenges a user to a game. The ElectroServerAS .challengeReceived event is triggered on the challengee's computer. The property ElectroServerAS.challenging is set to true. Example: The following line is an example of how to challenge a user: ElectroServerAS.challenge("jobem","Mini Golf") ElectroServerAS.challengeAnsweredUsage: ElectroServerAS.challengeAnswered(which)
Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when a person you have challenged responds to that challenge. If the user accepts your challenge, which is "accepted". If the user declines your challenge, which is "declined". If for any number of reasons the user's Flash client declines your challenge automatically, which is "autodeclined". Example: The following lines create a function to be called when a challenge request is answered: function challengeAnswered(which) { if (which == "accepted") { _root.gotoAndStop("game"); } else if (which == "declined") { trace("declined"); } else if (which == "autodeclined") { trace("auto declined"); } } ElectroServerAS.challengeAnswered = this.challengeAnswered; ElectroServerAS.challengeCancelledUsage: ElectroServerAS.challengeCancelled Parameters: None. Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when a challenge request that has been sent to you is cancelled. ElectroServerAS.challengeReceivedUsage: ElectroServerAS.challengeReceived(who, game)
Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when a challenge is received. You can be challenged to a game by other users. The who parameter contains the user name of the person who challenged you, and the game parameter contains the name of the game. ElectroServerAS.challengingUsage: ElectroServerAS.challenging Description: Property; this is a Boolean value. If true, then a challenge has been sent and no response has yet been received. If, while this is true, you are challenged, then an automated decline message is sent back to the challenger. If challenging is not true, then you can receive challenges. This property is used internally by the ElectroServerAS object. ElectroServerAS.chatReceiverUsage: ElectroServerAS.chatReceiver(info)
Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when a chat message is received. When this method is called, an object is passed in. The properties of this object are from, type, and body. The from property is the user name of the person who sent the message. The type property is the type of message that arrived. If type is "public", then it is a message to the room; if type is "private", then it is a private message to you. The body property is a string value that contains the chat message. Example: The following lines create a function that is to be called when a message is received: function messageArrived(info) { var from = info.from; var type = info.type; var body = info.body; if (type == "public") { var msg = from+": "+body+newline; } else if (type == "private") { var msg = from+"(private): "+body+newline; } chat.window.text = ES.addToHistory(msg); chat.bar.setScrollPosition(chat.window.maxscroll); } ElectroServerAS.chatReceiver = this.messageArrived; ElectroServerAS.connectToServerUsage: ElectroServerAS.connectToServer() Parameters: None. Returns: Nothing. Description: Method; this method uses the ElectroServerAS.port and ElectroServerAS.IP properties, and initializes a socket connection with the ElectroServer socket server. See ElectroServerAS.port and ElectroServerAS.IP for more information. Example: The following line makes a connection with the ElectroServer socket server: ElectroServerAS.connectToServer() ElectroServerAS.createVariableUsage: ElectroServerAS.createVariable(name, value, deleteOnExit, lock)
Returns: Nothing. Description: Method; creates or updates a variable in your current room on the socket server. Whenever a variable is created, updated, or deleted, all users in that room are informed via the ElectroServerAS.roomVariablesChanged event. All room variables are stored in an object on the ElectroServerAS object called roomVars. Example: The following line creates a room variable: ElectroServerAS.createVariable("secret_door","door3",true,false) ElectroServerAS.deleteVariableUsage: ElectroServerAS.deleteVariable(name)
Returns: Nothing. Description: Method; deletes a room variable of the name you specify. The variable is deleted even if it is locked (see ElectroServerAS.createVariable()). Once it's deleted, all users in that room are informed. Example: The following line deletes a room variable: ElectroServerAS.deleteVariable("secret_door") ElectroServerAS.disconnectFromServerUsage: ElectroServerAS.disconnectFromServer() Parameters: None. Returns: Nothing. Description: Method; closes the connection between Flash and the ElectroServer socket server. Example: The following line disconnects the Flash client from the ElectroServer socket server: ElectroServerAS.disconnectFromServer() ElectroServerAS.getHistoryUsage: ElectroServerAS.getHistory() Parameters: None. Returns: The string ElectroServerAS.history. Description: Method; returns the chat history. The chat history is stored as a string in ElectroServerAS.history and gets added to using the ElectroServerAS.addToHistory() function. Example: The following line sets a variable from the chat history: myHistory = ElectroServerAS.getHistory() ElectroServerAS.getRoomListUsage: ElectroServerAS.getRoomList() Parameters: None. Returns: An array of objects. Description: Method; returns an array. Each element of the array is an object that describes a room and has two properties: name and total. The property name is the name of the room; the property total is the number of people in that room. Example: The following ActionScript loops through the room list and shows the names and number of people in each room in the output window: var theRooms = ElectroServerAS.getRoomList(); for (i in theRooms) { trace(theRooms[i].name); trace(theRooms[i].total); } ElectroServerAS.getUserListUsage: ElectroServerAS.getUserList() Parameters: None. Returns: An array of objects. Description: Method; returns an array. Each element of the array is an object that describes a user and has only one property: name. The property name is the user name of one person in your room. Example: The following ActionScript loops through the room list and shows the names and number of people in each room in the output window: var theUsers = ElectroServerAS.getUserList(); for (i in theUsers) { trace(theUsers[i].name); } ElectroServerAS.historyUsage: ElectroServerAS.history Description: Property; this is a string value that stores the chat history. Currently this method just returns the history property. However, in future revisions of the ElectroServerAS object, the history may be stored in a different manner, in which case the getHistory() method will be more useful. So it would be a good idea to get into the practice of using the ElectroServerAS.getHistory() method. Example: The following line is an example usage of this property: myHistory = ElectroServerAS.history ElectroServerAS.inGameUsage: ElectroServerAS.inGame Description: Property; this is a Boolean value (true or false). If it's true, then you are currently in a game. If it's false, then you are not currently in a game. If you receive a challenge and ElectroServerAS.inGame has a value of true, then a decline message is sent automatically. This property is used internally by the ElectroServerAS object. ElectroServerAS.ipUsage: ElectroServerAS.ip Description: Property; stores the IP address of the server you wish to connect to. It (as well as ElectroServerAS.port) must be set before the ElectroServerAS.connectToServer() method will perform properly. This can be the numeric IP address of a server or the domain name (such as "23.244.81.5" or "macromedia.com"). Example: ElectroServer = new ElectroServerAS(); ElectroServerAS.ip = "localhost"; ElectroServerAS.port = 8080; ElectroServerAS.connectToServer(); ElectroServerAS.isRespondingUsage: ElectroServerAS.isResponding Description: Property; this is a Boolean value (true or false) used internally by the ElectroServerAS object. If you receive a challenge, this property is set to true. If while it's true you receive another challenge, a decline message is automatically sent. Once you respond to this challenge by either accepting it or declining it, isResponding is set to false. ElectroServerAS.joinRoomUsage: ElectroServerAS.joinRoom(name)
Returns: Nothing. Description: Method; changes the room you are in to the room specified in the name parameter. If the room does not yet exist, then it is created. The name of the room you have chosen to join is stored in the property ElectroServerAS.myRoom. Example: The following line changes the room you are in to "Lobby": ElectroServerAS.joinRoom("Lobby") ElectroServerAS.kickUsage: ElectroServerAS.kick(who, why)
Returns: Nothing. Description: Method; disconnects a user from the ElectroServer socket server. You must have administrator-level access to the server in order to initiate this method. Example: The following line kicks a user from the server: ElectroServerAS.kick("meanie") ElectroServerAS.leaveAloneUsage: ElectroServerAS.leaveAlone Description: Method; this is a Boolean value (true or false); the default is false. If true, then all incoming challenge requests will automatically be declined. ElectroServerAS.loginUsage: ElectroServerAS.challenge(name, password)
Returns: Nothing. Description: Method; logs in a user to the server. If a password is used, the log-in information is compared with the user name and passwords listed for administrator-level users. If no password is used, the user is just logged in. An administrator is created using tools provided with the ElectroServer socket server. Example: The following line logs in the user: ElectroServerAS.login("jobem") The following line logs in the user as an administrator: ElectroServerAS.login("important_person","his_password") ElectroServerAS.loginResponseUsage: ElectroServerAS.loginResponse(success, reason)
Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when a response has been received from the server after a log-in has been attempted. The first parameter, success, is true if the log-in was a success and false if it was not. If the log-in failed (success false) then the reason parameter (a string value that contains the reason why the log-in attempt failed) is passed in. Example: The following lines create a function that is to be called when a response to the log-in attempt is received: function loginResponse(success, reason) { if (success) { ElectroServerAS.joinRoom("Lobby"); chat.gotoAndStop("chat"); } else { trace("reason="+reason); } } ElectroServerAS.loginResponse = this.loginResponse; ElectroServerAS.moveReceivedUsage: ElectroServerAS.moveReceived(object)
Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when an opponent sends you a move in a game. This custom object can contain any data type, including arrays, XML objects, and variables. Example: The following lines create a function and set that function to be called when a move is received. The function simply traces the names and values of all properties of the custom object passed in. function moveReceived(ob) { for (i in ob) { trace(i+"="+ob[i]); } } ElectroServerAS.moveReceived = this.moveReceived; ElectroServerAS.myRoomUsage: ElectroServerAS.myRoom Description: Property; stores as a string the name of the room you are currently in. ElectroServerAS.onConnectionUsage: ElectroServerAS.onConnection(success)
Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when a connection to the ElectroServer socket server has been established and verified. A value of true is passed into the callback function if the connection was a success; a value of false is passed in if it was not. The server must successfully send a message verifying that the connection is valid before this event is fired. In other words, making the connection to the server is not enough to fire this event you need confirmation of the connection. Example: The following lines create a function that is to be called when a connection to ElectroServer is established and verified: function connectionResponse(success) { if (success) { chat.gotoAndStop("login"); } else { trace("connection failed"); } } ElectroServerAS.onConnection = this.connectionResponse; ElectroServerAS.onPlayersInRoomChangeUsage: ElectroServerAS.onPlayersInRoomChange(num)
Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when the number of people in your room changes. This happens whenever a person joins or leaves your room. Example: The following lines create a function and set it to be called when the number of people in your room changes. The function checks to see if there are two people in your room. If there are, then it is time to initialize the game (assuming it is a two-player game). function numPlayers(num) { if (num == 2) { startGame(); } } ElectroServerAS.onPlayersInRoomChange = this.numPlayers; ElectroServerAS.onRoomVarChangeUsage: ElectroServerAS.onRoomVarChange(roomVars, type, name)
Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when the list of variables associated with your current room (stored on the socket server) changes or when you first enter a room. When you first enter a room, this event occurs and you are sent a list of all of the variables in that room. The type parameter is "list" when this happens. When a variable in your room is created or modified, then the type parameter is "update" and the name parameter contains a string name of the variable that changed (or was created). When a variable in your room is deleted, then the type parameter is "delete", and the name parameter contains a string name of the variable that has been deleted. ElectroServerAS.opponentUsage: ElectroServerAS.opponent Description: Property; stores the name of your opponent. This property is created when you and another person have agreed to play a game. ElectroServerAS.playerUsage: ElectroServerAS.player Description: Property; stores your "player number" within a game. If you are in a game with only two players, then this property has a value of 1 for one person and a value of 2 for the other. Example: The following is an example of a snippet of code you might find at the beginning of a chess game: if (ElectroServerAS.player == 1) { myChessPieceColor = "white"; } else if (ElectroServerAS.player == 2) { myChessPieceColor = "black"; } ElectroServerAS.portUsage: ElectroServerAS.port Description: Property; stores the IP address of the server you wish to connect to. It must be set (as well as ElectroServerAS.ip) before the ElectroServerAS.connect() method will perform properly. This can be the numeric IP address of a server or the domain name (for example, "23.244.81.5" or "macromedia.com"). Example: ElectroServer = new ElectroServerAS(); ElectroServerAS.ip="localhost"; ElectroServerAS.port=8080; ElectroServerAS.connect(); ElectroServerAS.roomListChangedUsage: ElectroServerAS.roomListChanged(rooms)
Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when the list of visible rooms changes. When it's called, an array is passed in. Each element in the array is an object representing a room with the properties name and total. The name property is the name of the room, and total is the number of people in that room. Example: The following lines create a function and set it to be called when the room list changes. The function populates a text field with room names that take the format Lobby(32). function roomListChanged(roomList) { roomList.text = ""; for (var i = 0; i<roomList.length; ++i) { chat.roomList.text += roomList[i].name+" ("+roomList[i].total+")"+newline; } } ElectroServerAS.roomListChanged = this.roomListChanged; ElectroServerAS.roomsUsage: ElectroServerAS.rooms Description: Property; an array that stores information about each room. Every element in the array is an object with the properties of name and total. The name property contains the name of the room; total is the number of people in that room. It is recommended to use the ElectroServerAS.getRoomList() method; currently ElectroServerAS.getRoomList() just returns the rooms property, but in future revisions of the ElectroServerAS object, the room list may be stored in a different way. ElectroServerAS.roomVarsUsage: ElectroServerAS.roomVars Description: Property; an object that stores the room variables. Every time a variable is created, updated, or deleted from the server, it is also reflected in this object. If you define an event handler using ElectroServerAS.onRoomVarChange, you will be informed when this happens. Example: The following example shows the names of all the server variables in the output window, along with their values: ob = ElectroServerAS.roomVars; for (i in ob) { trace(i+"="+ob[i]); } ElectroServerAS.sendDataUsage: ElectroServerAS.send Data(msg)
Returns: Nothing. Description: Method; sends the information found in the msg parameter to the server. This method is used internally by the ElectroServerAS object, and it is unlikely to be needed for anything other than extending the ElectroServerAS object. ElectroServerAS.sendMessageUsage: ElectroServerAS.sendMessage(msg, who)
Returns: Nothing. Description: Method; sends a chat message to the room or to a user. This is the method used for regular chatting and private messaging. Example: The following line sends a message to the room: ElectroServerAS.sendMessage("Good morning Raleigh!","All") The following line sends a message to "jobem": ElectroServerAS.sendMessage("Hey man, where've you been?","jobem") ElectroServerAS.sendMoveUsage: ElectroServerAS.sendMove(who, what)
Returns: Nothing. Description: Method; sends an object to the specified user. The object is of type object and can contain any other data objects, such as arrays, date objects, or XML objects. This method is how moves are made in a game. Example: The following sends a move to "jobem": myObject=new Object(); myObject.ball_x=32; myObject.ball_y=413; ElectroServerAS.sendMove("jobem",myObject); ElectroServerAS.sendSystemMessageUsage: ElectroServerAS.sendSystemMessage(msg)
Returns: Nothing. Description: Method; sends a message to every user in every room on the server. This is only available to users with administrator-level access to the server. Example: The following line of ActionScript sends a message to everyone connected to the server: ElectroServerAS.sendSystemMessage("The server is about to be rebooted. Please refresh in 1 minute.") ElectroServerAS.userListChangedUsage: ElectroServerAS.userListChanged(users)
Returns: Nothing. Description: Method; a callback function invoked by the ElectroServerAS object when the list of users in your room changes. When you first enter a room, this event occurs, and you are sent a list of all the users in the room. The users parameter is an array of objects. Each object represents one user and has one property, name, which stores the user name of the user whom it represents. Example: These lines of ActionScript create a function and set it to be called whenever the list of users in the room changes. The function uses the Flash ListBox component to display the list of users. function userListChanged(userList) { var path = chat.userList; path.removeAll(); for (var i = 0; i<userList.length; ++i) { path.addItem(userList[i].name); } } ElectroServerAS.userListChanged = this.userListChanged; ElectroServerAS.usernameUsage: ElectroServerAS.username Description: Property; the name with which you are logged in. ElectroServerAS.usersUsage: ElectroServerAS.users Description: Property; an array of objects. Each object represents a user in your room with one property, name, that stores the user name of that person. It is recommended that you use ElectroServerAS.getUserList() to retrieve the user list. In future revisions of this object, the user list may be stored differently. ElectroServerAS.usersInMyRoomUsage: ElectroServerAS.usersInMyRoom Description: Property; an integer that specifies the total number of people in your room. new ElectroServerAS()Usage: new ElectroServerAS() Parameters: None. Returns: Nothing. Description: Constructor; creates a new ElectroServerAS object. You must use the constructor method to create an instance of the ElectroServerAS object before calling any of the ElectroServerAS object methods. Example: The following line creates an instance of the ElectroServerAS object with a reference of ES: ES = new ElectroServerAS(); |