EmHosting
Core class of everMany’s lobby and room API.
Hosting
| public static function get Hosting():EmHosting |
{EmHosting} Access to the single global EmHosting object; initialized using Create. Valid only after a call to the constructor, or more typcially: Create.
Create
| public static function Create( | sprite: | Sprite | ):EmHosting |
|
Create an instance of the everMany Hosting API.
Parameters
| sprite | Your game’s main display object. If you are using a preloader, this should be the loaded sprite -- ( ie. your core game ), not the preloader itself. |
Throws
currentArea
| public function get currentArea():EmArea |
{EmArea} Your current location. Always an EmRoom, EmLobby, or EmServer. No more than one EmArea object can be valid at a time because you can’t be in more than one place at a time.
status
| public function get status():NetStatus |
{NetStatus} Current state of your connection to your EMP server.
connect
| public function connect( | playerName: | String, | | | | shard: | EmpShard | = | null | ):void |
|
Connect to an EMP server. You must connect to a server before you can enter lobbies and rooms, start multiplayer games, or chat with other players. Connecting to a server takes time, runFrame() will yield an EmMessage.CONNECTED when the transition finishes.
Parameters
| playerName | {flash.String} Desired name of the local player. Will be transmitted to all remote clients. Note: We recommend you use EmString to strip html tags out of player names. |
| shard | {EmpShard} (optional) EMP server group that you would like to connect to. Note: the server group itself will ultimately decide which particular server within the group you will enter. |
Throws
createRoom
| public function createRoom( | config: | EmpChannelConfig | = | null | ):EmRoom |
|
Create and enter a new room. Creating a room takes time, runFrame() will first yield EmMessage.CREATED_ROOM and then later EmMessage.ENTERED_ROOM once the process has finished.
Parameters
| config | {EmpChannelConfig} (optional) Descripition of the room that you would like to create. |
Returns
The new EmRoom that you have created and are transitioning into.
Throws
- IllegalOperationError - If you are not connected to a server, another area transition is pending, or if you are not currently in a lobby.
See Also
enterRoom
enterLobby
| public function enterLobby( | lobbyInfo: | EmLobbyInfo | ):EmLobby |
|
Move into an open lobby. Entering a lobby takes time, runFrame() will yield an EmMessage.ENTERED_LOBBY when the transition finishes.
Parameters
| lobbyInfo | {EmLobbyInfo} The info object describing the lobby you would like to enter. |
Returns
The EmLobby you are transitioning into.
Throws
Note
You can jump to any lobby at any time, so long as you are connected to the appropriate server.
enterRoom
| public function enterRoom( | roomInfo: | EmRoomInfo, | | | | password: | String | = | null | ):EmRoom |
|
Move from a lobby into an existing room. Entering a room takes time, runFrame() will yield an EmMessage.ENTERED_ROOM when the transition finishes.
Parameters
| roomInfo | {EmRoomInfo} The room you would like to enter. |
| password | {flash.String} (optional) Password specified when the room was created, if any. |
Returns
The EmRoom you are transitioning into.
Throws
- flash.ArgumentError - If the passed roomInfo is null.
- IllegalOperationError - If you are not connected to a server, another area transition is pending, or if you are not in the lobby that contains the requested room.
See Also
createRoom
leaveCurrentArea
| public function leaveCurrentArea():EmArea |
If you are in a room, go to its lobby; if you are in a lobby, go back to the server staging area. Leaving an area ( and entering a new area ) takes time, see enterRoom, enterLobby, and connect for more information.
Throws
- IllegalOperationError - If you are not connected to a server, another area transition is pending, or if you are current at the ‘server’ level.
Returns
The new EmArea you are transitioning to.
lockRoom
| public function lockRoom( | room: | EmRoom | ):void |
|
Stop new players from entering your current room.
runFrame
| public function runFrame():Array |
Exchange messages with the server. Should be called on a per frame, or near per frame, basis. We recommend calling this at least 10 times a second, but never more than once in a single frame.
Returns
flash.Array containing EmMessages.
Note
Calling runFrame() multiple times in a single frame will not accelerate the speed at which your messages reach the server.
See Also
flash.events.Event ENTER_FRAME
sendChat
| public function sendChat( | string: | String, | | | | toWhom: | EmPlayerInfo | = | null, | | sanitize: | Boolean | = | true | ):void |
|
Send text from the local client to one or all players in your current area. Remote players will receive an EmMessage.GOT_CHAT when the text arrives on their machine. The EmMessage.context will contain the text you sent and the EmMessage.source will contain the EmPlayerInfo that describes you.
We recommend that you use EmString to strip out html tags out of all chat. Please note: Strings of zero length are silently culled.
Throws
Parameters
| string | {flash.String} Text to send. |
| toWhom | {EmPlayerInfo} ( optional ) Player to send the data to. If null ( the default ) goes to all players in your current area. Note: You can only communicate with players who are in your current area. |
| sanitize | {flash.Boolean} ( default true ) When true: strip html tags, starting and ending spaces from chat. |
sendData
| public function sendData( | bytes: | ByteArray, | | | | toWhom: | EmPlayerInfo | = | null | ):void |
|
Send binary data from the local client to one or all players in your current area. Remote players will receive an EmMessage.GOT_DATA when the data arrives on their machine. The EmMessage.context will contain the bytes you sent and the EmMessage.source will contain the EmPlayerInfo that describes you.
You can send up to a few kilobytes at a time, but the larger the data: the longer it will take. Please note: data of zero length is silently culled.
Throws
Parameters
| bytes | flash.utils.ByteArray Data to send, starting from current bytes.position. |
| toWhom | ( optional ) Player to send the data to. If null ( the default ) goes to all players in your current area.? Note: You can only communicate with players who are in your current area. |
shutdown
| public function shutdown():void |
Disconnect from the server and cleanup all local resources.
EmHosting
| public function EmHosting( | emp: | EmpFramework | ) |
|
The EmHosting constructor, but prefer using the static Create method instead. The raw constructor is not supported for general use at this time.
Throws