This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Status and People List
When the client disconnects, the server-side Status.removeClient( ) method is called.
It removes the entry for the client from the
status shared object:, null);
That was a fair bit to follow, and it’s easy to lose track of the big picture. In sum-
mary, the Status component’s addClient( ) method sets up each server-side
object so it can receive setStatus( ) calls from the client-side part of the Status compo-
nent. The addClient( ) method also updates the
status shared object so that the
user’s initial status is “Online”. From then on, whenever the user changes his status,
the series of events in Figure 13-4 will occur. Have a look at Figure 13-4 from top to
bottom to see how one event leads to another.
That’s it—you’ve seen all the pieces that make the Status component work. It’s time
to turn to designing and building the PeopleList component that will listen to the
status shared object and display the right icon for each user.
Designing and Building a PeopleList Component
The SimplePeopleList component introduced earlier was designed to be as simple as
possible in order to introduce the basic requirements of building a v2 Flash compo-
nent. It was not responsible for adding data to the
userList shared object and was
not capable of showing a user’s status. The PeopleList component addresses both
shortcomings. A server-side PeopleList object is used to maintain a
people shared
object to which the client-side PeopleList object connects (this replaces the
used in the SimplePeopleList component). Furthermore, if a Status component
passes a reference to the
status shared object to the PeopleList component, the lat-
ter also displays status icons; otherwise, PeopleList works correctly without display-
ing any icons.
Fortunately, the code for the PeopleList.asc file, which implements the server-side
PeopleList class is short and relatively simple, as shown in Example 13-7.
Example 13-7. The server-side PeopleList class definition from the PeopleList.asc file
function PeopleList(name) {
if (!name) name = "main"; = name;
this.path = "pfcs/" + this.className + "/" + name; = SharedObject.get(this.path + "/people");
PeopleList.prototype.className = "PeopleList";
PeopleList.prototype.addClient = function (client) {, client.pfcs.user);
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Chapter 13: Building Communication Components
The server-side PeopleList class does two things. It adds an entry for each user into
people shared object when the client connects, and it removes the entry when the
client disconnects. The entry it adds is an object that was passed into the application.
onConnect( ) method. (See the main.asc file listing in Example 13-5.) Creating a sepa-
rate shared object for the PeopleList component makes it possible to separate the
public from the private information passed in by the client and reduce shared object
updates to those needed by just the PeopleList component. In this example, the
object is just added to the PeopleList’s people shared object. In later chapters, only
public information is added.
The PeopleList component does not receive remote method calls from its client-side
counterpart the way the Status component does. The shared object path is in the
now-familiar path of pfcs/PeopleList/main/people.
The client-side PeopleList component contains the same asset as the
SimplePeopleList component—a List component. Much of the code in the client-side
PeopleList component is the same as the code in the SimplePeopleList component,
so the entire class definition is not reproduced here. See the file in the archive on the book’s web site for the complete listing. The setter
method that is passed a NetConnection object is almost identical. The only differ-
ence is that it gets a shared object at the path
path + "people" instead of the path
resourcePath + "userList" used by the SimplePeopleList component. In either case,
the client-side PeopleList component uses the NetConnection object to get a refer-
ence to the remote shared object, sets itself as listener on it, and connects it. The Peo-
pleList class has an additional setter method that can be used to pass a reference to a
status_so shared object to it, as shown in the client-side code in Example 13-8.
PeopleList.prototype.removeClient = function (client) {, null);
PeopleList.prototype.close = function ( ) {
Example 13-8. Passing in a status shared object to the PeopleList component
public function set status_so (so:SharedObject) {
if (so instanceof SharedObject) {
__status_so = so;
__status_so.addEventListener("onSync", this);
list.iconFunction = function (item) {
var status =;
if (status) {
return "Status_Person_" + status;
if (__status_so.isConnected) {
Example 13-7. The server-side PeopleList class definition from the PeopleList.asc file (continued)

Get Programming Flash Communication Server now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.