Home
Documentation
Download
Forums
EasyCommunicator
Version 1.2 Documentation
Objects
EasyCommunicator
NameValue
Methods
setRequestPage
setVariable
send
load
Get
Properties
nvData
Events
EasyCommunicatorReady
EasyCommunicatorDataReceived
Server-side Code
PHP
ASP.NET
JSP/Java
Objects
EasyCommunicator
The EasyCommunicator object represents a connection to a server.
Using the Flash version makes EasyCommunicator work for older browsers without support for XMLHTTP requests. This gives you wider compatibility for your AJAX application. For the Flash version to work, you must have the following HTML on your page:
<DIV STYLE="position: absolute; left: -520; top:0;">
<SCRIPT LANGUAGE="javascript" SRC="EasyCommunicator.js"></SCRIPT>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
ID="communicator"
WIDTH="150" HEIGHT="125" ALIGN="">
<PARAM NAME=movie VALUE="EasyCommunicator.swf"> <PARAM NAME=loop
VALUE=false> <PARAM NAME=quality VALUE=low> <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="EasyCommunicator.swf" loop=false quality=low bgcolor=#FFFFFF WIDTH="150" HEIGHT="125" swLiveConnect=true ID="communicator" NAME="communicator" ALIGN=""
TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT>
</DIV>
<SCRIPT LANGUAGE="VBScript">
Sub communicator_FSCommand(ByVal command, ByVal args)
Call communicator_DoFSCommand(command, args)
End Sub
</SCRIPT>
Regardless of which version you implement, you must respond to two events called by the object, EasyCommunicatorReady and EasyCommunicatorDataReceived. The EasyCommunicatorReady event is called when the Flash file loads, or when the DOM script loads. Inside the ready event you create a new global EasyCommunicator object. EasyCommunicatorDataReceived is called when a response is received from the server after a call to send(), it passes the data returned by the server.
function EasyCommunicatorReady() {
oCom = new EasyCommunicator();
oCom.setRequestPage(REQUEST_URL);
oCom.setVariable("message", "I'm here!");
oCom.send();
}
function EasyCommunicatorDataReceived(sData) {
oCom.load(sData);
switch (oCom.nvData.Get("action")) {
case "hello" :
bConnected = true;
break;
case "message" :
message(oCom.nvData.Get("message"));
break;
}
oTimeout = window.setTimeout("query()", 3000);
}
NameValue
The NameValue object holds the data received from the server. You access the data through the get() method. To send data you use the setVariable method of the EasyCommunicator object and then call the send method:
function sendmessage() {
oCom.setVariable("action", "2");
oCom.setVariable("userid", document.forms["send"].elements["userid"].value);
oCom.setVariable("name", document.forms["send"].elements["name"].value);
oCom.setVariable("message", document.forms["send"].elements["message"].value);
oCom.setVariable("message", document.forms["send"].elements["message"].value);
oCom.send();
}
Methods
setRequestPage(sPage)
Sets the page requests will be sent to and data received from.
setVariable(sName, sValue)
Sets a field of sName with a value of sValue.
send()
Makes a HTTP POST request to the server with the data set using setVariable. If no variables were set makes a normal request and receives the response.
load(sData)
Loads the data (in the DataReceived event) into the nvData property.
Get(sName)
Returns data from the server of variable name sName.
Properties
nvData
NameValue object which makes data accessible once the load() method is called.
Events
EasyCommunicatorReady()
Called when the Flash movie loads.
EasyCommunicatorDataReceived(sData)
Called when a response is received from the server.
Server-side Code: PHP
EasyCommunicator includes a simple set of functions for receiving and sending data from EasyCommunicator in PHP. You'll include EasyCommunicator.php to use these functions.
loadclientvars()
Loads data sent using the send method, returns a reference to the loaded data.
getclientvar($data, $varname)
Gets variable named $varname from loaded data $data.
setclientvar($data, $varname, $varvalue)
Sets variable named $varname in loaded data $data to $varname.
clientvarstring($data)
Returns a string you can print to the page to send data back to EasyCommunicator.
$clientvars = loadclientvars();
$action = getclientvar($clientvars, "action");
switch ($action) {
case "CREATEUSER" :
// create a new user and set $userid
// ...
$clientvars = clientvararray();
$clientvars = setclientvar($clientvars, "action", "started");
$clientvars = setclientvar($clientvars, "userid", $userid);
print(clientvarstring($clientvars));
break;
}
Server-side Code: ASP.NET
EasyCommunicator includes a .NET object (written in C#) for use in ASP.NET applications. You'll include EasyCommunicatorCommand.cs.
Constructors
Command(string sMessage)
Loads data sent using the send method, pass it data from either the "d" or the "s" request field.
Command()
Creates an empty Command object.
Properties
useDom
If sMessage above comes from "d" then set this to true (Note: the PHP version does this automatically and the C# version could, but doesn't).
useFlash
If sMessage above comes from "s" then set this to true (Note: the PHP version does this automatically and the C# version could, but doesn't).
Methods
bool hasVariable(String sName)
Checks whether variable sName exists.
String getVariable(string sName)
Returns the value of variable sName as a string.
int getVariableInt(string sName)
Returns the value of variable sName as an int.
setVariable(string sName, string sValue)
Sets variable sName to string value sValue.
setVariable(string sName, int iValue)
Sets variable sName to int value iValue.
string ToString()
Returns string that you may output to the page to send data to EasyCommunicator (Warning: set either useDom or useFlash to true first!).
Server-side Code: JSP - Java
EasyCommunicator includes a Java object for use in JSP applications. You'll include EasyCommunicatorCommand.java.
Constructors
Command(string sMessage)
Loads data sent using the send method, pass it data from either the "d" or the "s" request field.
Command()
Creates an empty Command object.
Properties
useDom
If sMessage above comes from "d" then set this to true (Note: the PHP version does this automatically and the C# version could, but doesn't).
useFlash
If sMessage above comes from "s" then set this to true (Note: the PHP version does this automatically and the C# version could, but doesn't).
Methods
bool hasVariable(String sName)
Checks whether variable sName exists.
String getVariable(string sName)
Returns the value of variable sName as a string.
int getVariableInt(string sName)
Returns the value of variable sName as an int.
setVariable(string sName, string sValue)
Sets variable sName to string value sValue.
setVariable(string sName, int iValue)
Sets variable sName to int value iValue.
string toString()
Returns string that you may output to the page to send data to EasyCommunicator (Warning: set either useDom or useFlash to true first!).
Server-side Code: Other
Writing server-side code to connect with EasyCommunicator is simply a matter of parsing and creating EasyCommunicator's data structure, which is very simple. If you create functions/objects for using EasyCommunicator with other platforms, please share it!