Package | com.smartfoxserver.v2.requests |
Class | public class ExtensionRequest |
Inheritance | ExtensionRequest com.smartfoxserver.v2.requests.BaseRequest |
This request is used to send custom commands from the client to a server-side Extension, be it a Zone-level or Room-level Extension. Viceversa, the extensionResponse event is used by the server to send Extension commands/responses to the client.
Read the SmartFoxServer 2X documentation about server-side Extension for more informations.
The ExtensionRequest request can be sent using the UDP protocol too, provided it is available (see the SmartFox.udpAvailable property): this allows sending fast stream of packets to the server in real-time type games, typically for position/transformation updates, etc.
See also
Method | Defined By | ||
---|---|---|---|
Creates a new ExtensionRequest instance. | ExtensionRequest |
ExtensionRequest | () | Constructor |
public function ExtensionRequest(extCmd:String, params:ISFSObject = null, room:Room = null, useUDP:Boolean = false)
Creates a new ExtensionRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
ParametersextCmd:String — The name of the command which identifies an action that should be executed by the server-side Extension.
| |
params:ISFSObject (default = null ) — An instance of SFSObject containing custom data to be sent to the Extension. Can be null if no data needs to be sent.
| |
room:Room (default = null ) — If null , the specified command is sent to the current Zone server-side Extension; if not null , the command is sent to the server-side Extension attached to the passed Room.
| |
useUDP:Boolean (default = false ) — If true , the UDP protocol is used to send the request to the server (check the SmartFox.udpAvailable property for more informations).
|
See also
private function someMethod():void { sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, onExtensionResponse); // Send two integers to the Zone extension and get their sum in return var params:ISFSObject = new SFSObject(); params.putInt("n1", 26); params.putInt("n2", 16); sfs.send(new ExtensionRequest("add", params)); } private function onExtensionResponse(evt:SFSEvent):void { if (evt.params.cmd == "add") { var responseParams:ISFSObject = evt.params.params as SFSObject; // We expect an int parameter called "sum" trace("The sum is: " + responseParams.getInt("sum")); } }