|
Home > Archive > Macromedia Flash Server > April 2005 > Populating UsersList with OnSync?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Populating UsersList with OnSync?
|
|
| Brandon_Krakowsky-A5pIpylr7pFSljaRc5+PrA@publi 2005-04-07, 8:45 pm |
| I have a customized UsersList Component which works similarly to the
FlashComm PeopleList Component, only with more features.
Usernames are stored in a shared object. Instances of the List & ComboBox
components are populated with a simple onSync Handler. The List Component
is for the Attendance List, whereas the ComboBox is for Text Chat.
Each slot in the shared object contains an object with 2 properties. One
for username and one for the "state" of the user. e.g. If they have
clicked on the question mark button, a question mark will appear next to
their name in the Attendee list.
The onSync handles each slot and populates the correct Components,
depending on whether or not the user is a Participant vs. Presenter, or if
the "allowPrivate" slot has been set to True or False.
This works well, unless there are several people all logging in or out at
once. The onSync temporarily freezes the movie. The onSync seems like
the easiest way to do this since you can be sure that the list is
accurate.
Any suggestions on a better way to do this? Should I still use an onSync,
but cross-reference each user slot with the UsersList in the List
Component? How can I tell which slots have actually changed, each time
the onSync is fired?
Or should I not use an onSync at all, just create functions which will
populate the list, subtract a name if someone logs out, add a name if
someone logs in, or change the appearance of a User entry in the list
based on their "state"?
Or, should I keep all users in an array, and then just bind the array to
the List Component?
Hopefully, this makes sense.
Thanks again,
Brandon
******************************
this.users_so = SharedObject.getRemote(this.prefix + "users", this.nc.uri,
false);
this.users_so.owner = this;
this.users_so.setFps(3);
this.users_so.onSync = function(list) {
_root.people_lb.removeAll();
this.owner.people_cb.removeAll();
this.owner.people_cb.addItem("*All Presenters", "*allpresenters");
if (_global.speakerMode == true || this.data.allowPrivate == true)
{
this.owner.people_cb.addItem("*Everyone", "*everyone");
};
var totalUsers = 0;
var totalLurkers = 0;
var totalQuest = 0;
var totalCheck = 0;
var totalEx = 0;
for (var i in this.data) {
if (this.data[i] == " fc_lurker") {
totalLurkers++;
} else {
if (this.data[i] != null) {
var user_obj = this.data[i];
if ((user_obj.x.indexOf("true") == -1) ||
(user_obj.x.indexOf("false") == -1)) {
totalUsers++;
// participant remarks
if (user_obj.y == null) {
var frameNum = 1;
} else {
var frameNum = user_obj.y;
};
if (_global.speakerMode == true) {
_root.people_lb.addItem({label:user_obj.x, data:i, state:frameNum});
this.owner.people_cb.addItem(user_obj.x, i);
_root.marksCount._visible
= true;
_root.participants_txt.text = "Users: " + totalUsers;
if (frameNum == 2) {
totalQuest++;
} else if (frameNum == 3)
{
totalCheck++;
} else if (frameNum == 4)
{
totalEx++;
};
_root.marksCount.partQuest.text = totalQuest;
_root.marksCount.partCheck.text = totalCheck;
_root.marksCount.partEx.text = totalEx;
//Set Private Chat
CheckBox to correct state
if (this.data.allowPrivate
== true) {
_root.info_mc.allowPrivate.selected = true;
} else if
(this.data.allowPrivate == false) {
_root.info_mc.allowPrivate.selected = false;
};
} else {
if (this.data.allowPrivate
== false || this.data.allowPrivate == null) {
//add just
presenters for private chat only
if
(((user_obj.x.indexOf("*") != -1) && (user_obj.x.indexOf(" (Presenter)")
!= -1)) || (user_obj.x == _root.chat_mc.username)) {
_root.people_lb.addItem({label:user_obj.x, data:i, state:frameNum});
};
_root.marksCount._visible = false;
_root.participants_txt.text = "";
} else {
_root.people_lb.addItem({label:user_obj.x, data:i, state:frameNum});
this.owner.people_cb.addItem(user_obj.x, i);
_root.marksCount._visible = true;
_root.participants_txt.text = "Users: " + totalUsers;
if (frameNum == 2)
{
totalQuest++;
} else if
(frameNum == 3) {
totalCheck++;
} else if
(frameNum == 4) {
totalEx++;
};
_root.marksCount.partQuest.text = totalQuest;
_root.marksCount.partCheck.text = totalCheck;
_root.marksCount.partEx.text = totalEx;
}
}
}
}
this.owner.people_cb.sortItemsBy("label", "ASC");
_root.people_lb.sortItemsBy("label", "ASC");
}
}
};
this.users_so.connect(this.nc);
=-----------------------------------------------------------
Supported by Fig Leaf Software - http://www.figleaf.com
=-----------------------------------------------------------
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcomm
| |
| Stefan Richter 2005-04-08, 7:45 am |
| The addItem and removeItem method should be avoided if possible. It more
robust to work with the list's dataprovider instead.
I couldn't explain it any better than Brian has done:
http://flash-communications.net/tec...sToArrays/index
..html
Version B is probably ok for you:
function onSync_b(list){
// Get the list's dataProvider and truncate it.
var dp = lb.dataProvider;
dp.splice(0);
// Fill the dataProvider using the native array method
// or your choice. In this example: push()
for (var p in so.data) {
dp.push({label:p, data:so.data[p]});
}
dp.dispatchEvent({target:dp, type:"modelChanged"});
}
The sorting can also be done using array methods.
Neato!
Stefan
> -----Original Message-----
> From: flashcomm-bounces-1Ss2GqJETD3yZ38Mhd3e/9ZfFG6BLHNm@public.gmane.org
> [mailto:flashcomm-bounces-1Ss2GqJETD3yZ38Mhd3e/9ZfFG6BLHNm@public.gmane.org] On Behalf Of
> Brandon_Krakowsky-A5pIpylr7pFSljaRc5+PrA@public.gmane.org
> Sent: 08 April 2005 00:36
> To: flashcomm-1Ss2GqJETD3yZ38Mhd3e/9ZfFG6BLHNm@public.gmane.org
> Subject: [FlashComm] Populating UsersList with OnSync?
>
> I have a customized UsersList Component which works similarly
> to the FlashComm PeopleList Component, only with more features.
>
> Usernames are stored in a shared object. Instances of the
> List & ComboBox components are populated with a simple onSync
> Handler. The List Component is for the Attendance List,
> whereas the ComboBox is for Text Chat.
>
> Each slot in the shared object contains an object with 2
> properties. One for username and one for the "state" of the
> user. e.g. If they have clicked on the question mark button,
> a question mark will appear next to their name in the Attendee list.
>
> The onSync handles each slot and populates the correct
> Components, depending on whether or not the user is a
> Participant vs. Presenter, or if the "allowPrivate" slot has
> been set to True or False.
>
> This works well, unless there are several people all logging
> in or out at once. The onSync temporarily freezes the movie.
> The onSync seems like the easiest way to do this since you
> can be sure that the list is accurate.
>
> Any suggestions on a better way to do this? Should I still
> use an onSync, but cross-reference each user slot with the
> UsersList in the List Component? How can I tell which slots
> have actually changed, each time the onSync is fired?
>
> Or should I not use an onSync at all, just create functions
> which will populate the list, subtract a name if someone logs
> out, add a name if someone logs in, or change the appearance
> of a User entry in the list based on their "state"?
>
> Or, should I keep all users in an array, and then just bind
> the array to the List Component?
>
> Hopefully, this makes sense.
>
> Thanks again,
> Brandon
>
> ******************************
>
> this.users_so = SharedObject.getRemote(this.prefix + "users",
> this.nc.uri, false); this.users_so.owner = this;
> this.users_so.setFps(3); this.users_so.onSync = function(list) {
> _root.people_lb.removeAll();
> this.owner.people_cb.removeAll();
>
> this.owner.people_cb.addItem("*All Presenters",
> "*allpresenters");
> if (_global.speakerMode == true ||
> this.data.allowPrivate == true) {
> this.owner.people_cb.addItem("*Everyone",
> "*everyone");
> };
>
> var totalUsers = 0;
> var totalLurkers = 0;
> var totalQuest = 0;
> var totalCheck = 0;
> var totalEx = 0;
>
> for (var i in this.data) {
>
> if (this.data[i] == " fc_lurker") {
> totalLurkers++;
> } else {
> if (this.data[i] != null) {
> var user_obj = this.data[i];
> if
> ((user_obj.x.indexOf("true") == -1) ||
> (user_obj.x.indexOf("false") == -1)) {
> totalUsers++;
>
> // participant remarks
> if (user_obj.y == null) {
> var frameNum = 1;
> } else {
> var frameNum
> = user_obj.y;
> };
>
> if
> (_global.speakerMode == true) {
> _root.people_lb.addItem({label:user_obj.x, data:i,
> state:frameNum}); this.owner.people_cb.addItem(user_obj.x, i);
>
> _root.marksCount._visible = true;
> _root.participants_txt.text = "Users: " + totalUsers;
> if (frameNum == 2) {
> totalQuest++;
> } else if
> (frameNum == 3) {
> totalCheck++;
> } else if
> (frameNum == 4) {
> totalEx++;
> };
> _root.marksCount.partQuest.text = totalQuest;
> _root.marksCount.partCheck.text = totalCheck;
> _root.marksCount.partEx.text = totalEx;
>
> //Set Private
> Chat CheckBox to correct state
> if
> (this.data.allowPrivate == true) {
> _root.info_mc.allowPrivate.selected = true;
> } else if
> (this.data.allowPrivate == false) {
> _root.info_mc.allowPrivate.selected = false;
> };
>
> } else {
> if
> (this.data.allowPrivate == false || this.data.allowPrivate == null) {
> //add
> just presenters for private chat only
> if
> (((user_obj.x.indexOf("*") != -1) && (user_obj.x.indexOf("
> (Presenter)") != -1)) || (user_obj.x ==
> _root.chat_mc.username)) {
> _root.people_lb.addItem({label:user_obj.x, data:i, state:frameNum});
> };
> _root.marksCount._visible = false; _root.participants_txt.text = "";
> } else {
> _root.people_lb.addItem({label:user_obj.x, data:i,
> state:frameNum}); this.owner.people_cb.addItem(user_obj.x,
> i); _root.marksCount._visible = true;
> _root.participants_txt.text = "Users: " + totalUsers;
> if
> (frameNum == 2) { totalQuest++;
> }
> else if (frameNum == 3) { totalCheck++;
> }
> else if (frameNum == 4) {
>
> totalEx++;
> };
> _root.marksCount.partQuest.text = totalQuest;
> _root.marksCount.partCheck.text = totalCheck;
> _root.marksCount.partEx.text = totalEx;
> }
> }
> }
> }
>
> this.owner.people_cb.sortItemsBy("label", "ASC");
> _root.people_lb.sortItemsBy("label", "ASC");
> }
> }
> };
>
> this.users_so.connect(this.nc);
>
> =-----------------------------------------------------------
> Supported by Fig Leaf Software - http://www.figleaf.com
> =-----------------------------------------------------------
>
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcomm
>
=-----------------------------------------------------------
Supported by Fig Leaf Software - http://www.figleaf.com
=-----------------------------------------------------------
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcomm
|
|
|
|
|