PDA

View Full Version : List Component Flex 2 Beta 3 AS3


Anunnakispirit
05-28-2006, 06:31 PM
Flex 2 Beta 3 : ActionScript 3!
I am writing a chat client with audio/video support, and I'm having a bit of a problem adding users to the list component. After alot of confusion I managed to actually get them to add to the list using an array. But when a user joins the room, it shows all the nicknames again. For Example. I join as Guest1, Guest 1 gets added to the list, then I join under another name e.g Guest2; on the Guest1 client it displays Guest1, Guest1, Guest2...Which says to me, it has added the array when they join, but then it fetches the details again and adds them to the list ontop of the other. There must be a way to refresh the list, like remove the values and readd the array items. I'm not sure how, and I've only been doing actionscript for two weeks. (Also I apologise if there was another thread on this, I did search, and looked through about 5 pages of returned search results but none were particularly useful to what I'm doing) Please help me if you can, thanks!

//This is at the top of the code where myarray is defined as an array
public var myarray:Array =[""];
[Bindable]
public var collection:ArrayCollection = new ArrayCollection();

//this is an event listener for users_so:SharedObject;
private function UserGetSync(event:SyncEvent):void
{
//Create a new array
var collection:ArrayCollection=new ArrayCollection(myarray);
for(var i:* in users_so.data) {
//users_so.data[i] is the nickname retrieved from FMS
if(users_so.data[i]!=null) {
//add the retrieved nickname from user_so.data[i] to the array
//There should be something here to refresh the NickList before adding users so it don't list on top of the last listing(which is where my problem lies)
collection.addItem(users_so.data[i]);
NickList.dataProvider=collection;
}
}

Tink
05-29-2006, 01:34 PM
The problem comes from 'myarray' not being refreshed.

Basically you ArrayCollections is made up of 'myarray', but you just keep adding to 'myarray' and therefore get duplicates.

Try//This is at the top of the code where myarray is defined as an array
public var myarray:Array;

//this is an event listener for users_so:SharedObject;
private function UserGetSync( event:SyncEvent ):void
{
// Create a new Array
myarray = new Array();

// Create new local ArrayCollection
var collection:ArrayCollection=new ArrayCollection( myarray );

for( var i:* in users_so.data )
{
//users_so.data[i] is the nickname retrieved from FMS
if( users_so.data[i] != null )
{
// Add the retrieved nickname from user_so.data[i]
// to the ArrayCollection
collection.addItem( users_so.data[ i ] );
}
}
// Add ArrayCollection to List
NickList.dataProvider=collection;
}

Anunnakispirit
05-29-2006, 06:25 PM
Thanks alot Tink, that worked great, but sadly I've run into another problem with actually allowing people to chat. I have webcam/audio and the nicklist working fine(some how lol) but now I'm not sure where I get the details from, I've looked through many examples in AS2 but flex examples seem to be a bit scarce, and as I'm new to actionscript I get a bit confused in the conversion process.

In my main.asc I have this

application.onConnect = function(newClient, name)
{
// Make this new client's name the user's name
newClient.name = name;

// Create a unique ID for this user while incrementing the
// application.nextID.
newClient.id = "u" + application.nextId++;

// Update the 'users_so' shared object with the user's name
application.users_so.setProperty(newClient.name, name);

// Accept the client's connection
application.acceptConnection(newClient);

// Call the client function 'setHistory,' and pass
// the initial history
newClient.call("setHistory", null, application.history);

// The client will call this function to get the server
// to accept the message, add the user's name to it, and
// send it back out to all connected clients.
newClient.msgFromClient = function(msg) {
msg = this.name + ": " + msg + "\n";
application.history += msg;
application.users_so.send("msgFromSrvr", msg);
}
}


which was taken from the FMS developer page. Here is the code for getting the message from the server in actionscript 2 I guess.

users_so.msgFromSrvr = function(msg) {

_root.History.text += msg;
_root.History.scroll = _root.History.maxscroll;
historyScroll.setScrollTarget(history);
historyScroll.setScrollPosition(_root.History.maxs croll);
}
}

basically what I need to know is howto get msgFromSrvr with the users_so object in actionscript3 in flex, it's a bit confusing for me, but I'm trying my best to work it out. I tried users_so.msgFromSrvr and it errored :( please help!

Pratik123
06-14-2006, 02:09 PM
Oh greate that u reached to make chat application with audio, video and text in ActionScript. I want to help you. But you i want to know the all codes for that...

nawin_g
06-20-2006, 10:39 AM
hey Anunnakisprit,

i am also running thru the same problem (converting code from AS2 to AS3).

can you plz mail me your code coz i am also working on a very similar project.

my mail id is : nawin_g@yahoo.com

tq,

mrmyers
10-10-2007, 05:57 PM
basically what I need to know is howto get msgFromSrvr with the users_so object in actionscript3 in flex, it's a bit confusing for me, but I'm trying my best to work it out. I tried users_so.msgFromSrvr and it errored :( please help!

Anunnakispirit,

Did you ever figure this one out? I am wrestling with the sam issue and have had no luck in finding documentation anywhere. Thank youfor your time and energy.

Nate