Hello Experts,
i have the following custom code to bind a <mx:List > control with the list of users currently logged in to the chatroom.
private function BindOnlineUsers():void
{
try
{
myUserId=cSession.userManager.myUserID;
//cSession.userManager.removeUser(myUserId);
userArray = cSession.userManager.userCollection;
if(userArray.length>0)
{
//Alert.show(UserDescriptor(userArray).userID.toString(),"list",Alert.OK);
//userArray.removeItemAt(0);//remove Host normally we have only one host
var totalUsers:Number=userArray.length;
var Users:Array=new Array();
var UserRole:int=50;
for( var i:uint=0; i < totalUsers ; i++)
{
if((userArray.getItemAt(i) as UserDescriptor).userID != myUserId && ((userArray.getItemAt(i) as UserDescriptor).role) != UserRoles.OWNER )
{
var userObject:Object=new Object();
userObject={userID:(userArray.getItemAt(i) as UserDescriptor).userID, displayName:UserDescriptor(userArray.getItemAt(i)).displayName};
Users.push(userObject);
}
}
Users.sortOn("displayName",Array.CASEINSENSITIVE);
lstOnlineUsers.dataProvider = Users;
lstOnlineUsers.labelField = "displayName";
lstOnlineUsers.data="userID";
//lstOnlineUsers.selectedIndex=0;
}
}
To synchronize with the service i have called a function "initializechatconsole" on creationcomplete event of session container as shown below:
<rtc:ConnectSessionContainer roomURL="{roomURL}" autoLogin="false" creationComplete="InitializeChatConsole();" authenticator="{auth}" id="cSession" width="100%" height="100%" >
in this function i have the code as shown below.see the line marked in red
private function InitializeChatConsole():void
{
try
{
m_chatModel.sharedID = "myChat";
m_chatModel.subscribe();
m_chatModel.addEventListener(ChatEvent.HISTORY_CHANGE, onHistoryChange);
cSession.userManager.userCollection.addEventListener(CollectionEvent.COLLECTION_CHANGE,onDataChange);
//cSession.streamManager.addEventListener(StreamEvent.STREAM_RECEIVE,onStreamRecieved);
chatOutput.addEventListener(ScrollEvent.SCROLL,onHistoryScroll);
chatOutput.verticalScrollPosition = chatOutput.maxVerticalScrollPosition;
BindOnlineUsers();
}
catch(e:Error)
{
Alert.show("Error: " + e.message,"Error",Alert.OK);
}
Now the ondatachange function has the following code as given below.
protected function onDataChange(p_evt:CollectionEvent):void
{
switch(p_evt.kind)
{
case CollectionEventKind.ADD:
BindOnlineUsers();
break;
case CollectionEventKind.REMOVE:
BindOnlineUsers();
break;
case CollectionEventKind.UPDATE:
BindOnlineUsers();
break;
}
}
the functionality of whole code is whenever a new user enters the room the usercollection changes and thus to display the new user in already logged in users RosterList i have to rebind it again.
now my proble is that whenever a new user enters the Roster list refreshes and if the user has selected any users go deselected automatically as the list rebinds again.
as i am new to flex development so please suggest me the best way to sort out this problem
Regards
Amit