Code

The readme.txt file in the download ZIP (linked to at the left) provides full instructions on installing and using the code.  Example document classes are provided.  Below is the operative code from the chat sample so that you get the idea.

Assuming that you import the Robin class as detailed in the ZIP file.

public function FloatChat() {

 // here we make a new Robin instance with paramerters of:
 // applicationName:String - application name
 // maxPeople:Number - maximum in a "room" (0 - unlimited)
 // fill:Boolean -  do you want to fill in where people left
 // initialProperties - starting properties as an object

 myRobin = new Robin("FloatChat", 3, true, {});

 // here are a couple Robin Events -
 // there is also OErrorEvent.IO_ERROR and Event.CLOSE
 // wait until the Event.CONNECT triggers before we start
 // DataEvent.DATA is when someone else sends data to you

 myRobin.addEventListener(Event.CONNECT, init);
 myRobin.addEventListener(DataEvent.DATA, receiveData);

}

private function init(e:Event) {

 // get past messages and put them in the message text field

 holder.myMessage.text = myRobin.history;

}

private function sendText(e:MouseEvent) {

 // below is how we can send more than one property at once
 // if we had used two setProperty methods:
 // myRobin.setProperty("name", currentName);
 // myRobin.setProperty("text", holder.myText.text);
 // then other people would receive two updates
 // these updates would go on two lines in their chat - boo
 // so we send an object using the object literal {}
 // with the properties we want to send

 myRobin.setProperties({name:holder.myName.text,
 text:holder.myText.text});            

 //we need to send our message to the history file as well
 // so new people can see older messages
 // this is "extra" as new people could just start fresh
 // history is cleared when all people in the room are gone    
 // it can be manually cleared with historyClear()

 var myMessage:String = holder.myName.text + ": "
+ holder.myText.text + "\n";
 myRobin.appendToHistory(myMessage);

}

private function receiveData(e:DataEvent) {

// put the Robin data into the message TextField:

 holder.myMessage.text += myRobin.getSenderProperty("name")
+ ": " + myRobin.getSenderProperty("text") + "\n";

}

One Response

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.