HI there every one, i have just started working with Flash Media Server, i need little help with Chat Application that i building. I have build up connection and an area where ever one can send message , now i want to make privatized chat, means to say if a person want to chat with another person who is online, what will i do , show me the right path, i am also trying get some solution , so if i come up with something i will share it,
Here is the Document Class for Flash
SharedText.as
package
{
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.ui.*;
import flash.text.*;
import fl.data.*;
import fl.events.*;
import fl.controls.*;
//import flash.net.ObjectEncoding;
import drmax.utils.*;
import com.greensock.*;
import com.greensock.easing.*;
import classes.*;
public class SharedText extends Sprite
{
private var _send:Button;
private var _connect:Button;
private var _txtArea:TextArea;
private var _txtInput:TextInput;
private var _nameInput:TextInput;
private var _nc:NetConnection;
private var _so:SharedObject;
private var _msg:Boolean;
private var _rtmpURL:String;
private var _responder:Responder;
private var _msgLabel:Label;
private var _nameLabel:Label;
private var _addUser:Responder;
private var _getUsers:Responder;
private var _friendsList:List;
private var _dp:DataProvider;
private var _connected:Boolean;
private var _tip:ToolTip;
private var _chatbox:ChatBox;
//-----------------/Constructor Check---------------------\\
public function SharedText ():void
{
//uncomment below line if using FMS prior then 3.0;
//NetConnection.objectEncoding = flash.net.ObjectEncoding.AMF0;
stage.addEventListener (KeyboardEvent.KEY_DOWN, checkKeys);
//create User Interface
createUI ();
//crete ToolTip
createToolTip ();
//connect to rtmp server
rtmpConnect ();
}
//-----------------/Constructor Check---------------------\\
//-----------------Create Basic UI---------------------\\
private function createUI ():void
{
//setup the text area
_txtArea = new TextArea;
_txtArea.setSize (450,300);
_txtArea.move (20,50);
_txtArea.editable = false;
_txtArea.condenseWhite = true;
addChild (_txtArea);
//add the name field
_nameLabel = new Label;
_nameLabel.text = "Name";
_nameLabel.move (20,360);
addChild (_nameLabel);
_nameInput = new TextInput;
_nameInput.move (_nameLabel.width-25,360);
addChild (_nameInput);
//setup text input
_msgLabel = new Label;
_msgLabel.text = "Message";
_msgLabel.move (20,390);
addChild (_msgLabel);
_txtInput = new TextInput;
_txtInput.setSize (250,35);
_txtInput.maxChars = 300;
_txtInput.enabled = false;
_txtInput.textField.wordWrap = true;
_txtInput.move (_msgLabel.width-25, 390);
addChild (_txtInput);
//add the button
_connect = new Button;
_connect.label = "Connect";
_connect.move (370,360);
_connect.addEventListener (MouseEvent.CLICK, connectClicked);
addChild (_connect);
//add the button
_send = new Button;
_send.label = "Send";
_send.move (370,390);
_send.enabled = false;
_send.addEventListener (MouseEvent.CLICK, sendClicked);
addChild (_send);
_friendsList = new List;
_friendsList.setSize (150, 300);
_friendsList.move (480,50);
_friendsList.addEventListener (ListEvent.ITEM_DOUBLE_CLICK, checkUser);
_friendsList.addEventListener (ListEvent.ITEM_ROLL_OVER, listRollOver);
_friendsList.addEventListener (ListEvent.ITEM_ROLL_OUT, listRollOver);
addChild (_friendsList);
}
//-----------------/Create Basic UI---------------------\\
//-----------------Create ToolTip---------------------\\
private function createToolTip ():void
{
_tip = new ToolTip("Some Tip text", true);
addChild (_tip);
_tip.showHide (false);
}
//-----------------/Create ToolTip---------------------\\
//-----------------Connect RTMP Server---------------------\\
private function rtmpConnect ():void
{
//setup the netConnection
_rtmpURL = "rtmp://192.168.0.222/basicSO";
//_rtmpURL = "rtmp://localhost/basicSO";
_nc = new NetConnection();
_nc.connect (_rtmpURL);
_nc.client = this;
_nc.addEventListener (NetStatusEvent.NET_STATUS, checkNetStatus);
_nc.addEventListener (AsyncErrorEvent.ASYNC_ERROR, checkAsyncError);
}
//-----------------/Connect RTMP Server---------------------\\
//-----------------/Net Status Check---------------------\\
private function checkNetStatus (eve:NetStatusEvent):void
{
_msg = eve.info.code == "NetConnection.Connect.Success";
if (_msg)
{
_txtArea.text = "Connected to Server.
";
_txtArea.appendText ("Please enter a name and press connect before chatting...
");
_so = SharedObject.getRemote("test", _nc.uri, false);
_so.connect (_nc);
_so.addEventListener (SyncEvent.SYNC, checkSync);
//initiate new users
_getUsers = new Responder(showUsers);
_nc.call ("getCurrentUsers", _getUsers);
}
else
{
_txtArea.text = "Cannot connected to Server. please refresh your browser.
";
}
}
//-----------------/Net Status Check---------------------\\
public function removeUser ():void
{
}
//-----------------/Add Current User to List---------------------\\
public function newUserAdded ():void
{
//get user list
_getUsers = new Responder(showUsers);
_nc.call ("getCurrentUsers", _getUsers);
//trace ("user added...!");
}
private function doAddedUser (success:String):void
{
trace (success);
//enable the chat bar
_txtInput.enabled = true;
_send.enabled = true;
_connected = true;
}
//-----------------/Add Current User to List---------------------\\
//-----------------get User List---------------------\\
private function showUsers (userList:Array):void
{
var totalUsers:Number = userList.length;
_dp = new DataProvider();
for (var i:int=0; i < totalUsers; i++)
{
if (userList* == _nameInput.text)
{
_dp.addItem ({ label: userList*, data:userList*});
}
else
{
_dp.addItem ({ label: userList*, data:userList*});
}
}
_friendsList.dataProvider = _dp;
}
//-----------------/get User List---------------------\\
//-----------------List Events---------------------\\
private function checkUser (eve:ListEvent):void
{
if (eve.item.label != _nameInput.text )
{
_chatbox = new ChatBox();
addChild(_chatbox);
}
}
private function listRollOver (eve:ListEvent):void
{
if (eve.item.label != _nameInput.text )
{
_tip.setText ("private chat : <b> " +eve.item.label+"</b>");
switch (eve.type)
{
case "itemRollOver" :
_tip.fadeIn ();
break;
case "itemRollOut" :
_tip.fadeOut ();
break;
}
}
}
//-----------------/List Events---------------------\\
//-----------------Connect User---------------------\\
private function connectChat ():void
{
//add currentUser to chat list;
if (_nameInput.text != "")
{
_addUser = new Responder(doAddedUser);
_nc.call ("addUser", _addUser, _nameInput.text);
_connect.enabled = false;
_nameInput.enabled = false;
}
else
{
_txtArea.appendText ("Name cannot be empty...
");
}
}
//-----------------/Connect User---------------------\\
//-----------------/Sending Messages---------------------\\
private function sendMessage ():void
{
if (_txtInput.text != "" && Number(_txtInput.text) != 0)
{
_so.setProperty ("msg", _nameInput.text +" : "+_txtInput.text);
_txtArea.appendText (_nameInput.text + " : " +_txtInput.text+"
");
_txtInput.text = new String();
_txtArea.verticalScrollPosition = _txtArea.maxVerticalScrollPosition;
}
}
//-----------------/Sending Messages---------------------\\
//-----------------Event Handelers---------------------\\
private function checkKeys (eve:KeyboardEvent):void
{
//trace (eve.target)
if (eve.keyCode == Keyboard.ENTER)
{
if (_connected)
{
sendMessage ();
}
else
{
connectChat ();
}
}
}
private function checkAsyncError (eve:AsyncErrorEvent):void
{
trace (eve.error);
}
private function connectClicked (eve:MouseEvent):void
{
connectChat ();
}
private function sendClicked (eve:MouseEvent):void
{
sendMessage ();
}
private function checkSync (eve:SyncEvent):void
{
for (var i:uint; i < eve.changeList.length; i++)
{
switch (eve.changeList*.code)
{
case "clear" :
break;
case "success" :
//trace (_so.data.msg);
break;
case "change" :
_txtArea.appendText (_so.data.msg+"
");
_txtArea.verticalScrollPosition = _txtArea.maxVerticalScrollPosition;
break;
}
}
}
//-----------------/Event Handelers---------------------\\
}
}
and below is the SSAS that i using
//Application first start
users = [];
application.onAppStart = function ()
{
trace ("test application has been started...!")
}
//when client tries to connect
application.onConnect = function (currentClient)
{
//accept the client if there is slot in array
application.acceptConnection(currentClient);
currentClient.addUser = function (uName)
{
users.push(uName);
for (i = 0; i < application.clients.length; i++){
application.clients*.call("newUserAdded");
}
return "user added successfully..!";
}
currentClient.getCurrentUsers = function ()
{
//return the property to client Object;
return users;
}
}
application.onAppStop = function (info){
trace("*** onAppStop called.");
if (info=="Application.Shutdown"){
application.entries_so.flush();
}
}
application.onDisconnect = function(currentClient)
{
//When currentClient leaves put the element back in array
users.pop(currentClient);
application.clearSharedObjects("/");
}
i will very thankful if any one can help me fast