EmHosting

Core class of everMany’s lobby and room API.

Summary
EmHostingCore class of everMany’s lobby and room API.
Static Properties
Hosting{EmHosting} Access to the single global EmHosting object; initialized using Create.
Static Methods
CreateCreate an instance of the everMany Hosting API.
Properties
currentArea{EmArea} Your current location.
status{NetStatus} Current state of your connection to your EMP server.
Methods
connectConnect to an EMP server.
createRoomCreate and enter a new room.
enterLobbyMove into an open lobby.
enterRoomMove from a lobby into an existing room.
leaveCurrentAreaIf you are in a room, go to its lobby; if you are in a lobby, go back to the server staging area.
lockRoomStop new players from entering your current room.
runFrameExchange messages with the server.
sendChatSend text from the local client to one or all players in your current area.
sendDataSend binary data from the local client to one or all players in your current area.
shutdownDisconnect from the server and cleanup all local resources.
EmHostingThe EmHosting constructor, but prefer using the static Create method instead.

Static Properties

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.

Static Methods

Create

public static function Create(sprite: Sprite):EmHosting

Create an instance of the everMany Hosting API.

Parameters

spriteYour 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

Properties

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.

Methods

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

bytesflash.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

public static function get Hosting():EmHosting
{EmHosting} Access to the single global EmHosting object; initialized using Create.
public function EmHosting(emp: EmpFramework)
The EmHosting constructor, but prefer using the static Create method instead.
public static function Create(sprite: Sprite):EmHosting
Create an instance of the everMany Hosting API.
public function get currentArea():EmArea
{EmArea} Your current location.
Base class for the player’s current location.
public function get status():NetStatus
{NetStatus} Current state of your connection to your EMP server.
Any string other than the above status cides represents a failure case.
public function connect(playerName: String,  
shard: EmpShard = null):void
Connect to an EMP server.
public function createRoom(config: EmpChannelConfig = null):EmRoom
Create and enter a new room.
public function enterLobby(lobbyInfo: EmLobbyInfo):EmLobby
Move into an open lobby.
public function enterRoom(roomInfo: EmRoomInfo,  
password: String = null):EmRoom
Move from a lobby into an existing room.
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.
public function lockRoom(room: EmRoom):void
Stop new players from entering your current room.
public function runFrame():Array
Exchange messages with the server.
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.
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.
public function shutdown():void
Disconnect from the server and cleanup all local resources.
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/ArgumentError.html
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/errors/IllegalOperationError.html
The current location of the player.
The current location of the player.
The current location of the player.
Sent in response to a successful EmHosting.connect.
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/String.html
Filter strings to provide some html sanity; replacing greater and less than signs with their unicode equivalents, and stripping trailing and leading whitespace.
An EMP server cluster.
Sent in response to a successful EmHosting.createRoom.
Sent in response to both successful EmHosting.enterRoom and EmHosting.createRoom calls.
Used to create new channels in conjuction with EmpFramework.createAndSubscribe.
Sent in respose to a successful EmHosting.enterLobby.
Description of a lobby that a player can enter.
Description of a room that a player can enter.
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/Array.html
Messages sent from the server are returned via EmHosting.runFrame.
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/events/Event.html
A remote player has something to tell you.
public function get context():*
{*} Data associated with this message.
public function get source():EmRemoteInfo
{EmRemoteInfo} The source of the message.
Description of a remote player.
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/Boolean.html
A remote player has sent you some data.
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/ByteArray.html
Close