Take the 2-minute tour ×

I'm creating an online game where people log in and then have the list of current players displayed. When the user enters a "room" it dispatches an SFSEvent which includes a Room object with the list of users as User objects in that room. As that event's callback function, I get the list of current users which is an Array, switch the View Stack child index, and then I wrap the user list array in an ArrayList before I assign it to the MXML Spark List component's dataSource. Here's my code:

My Actionscript Code Section (PreGame.as):

private function onRoomJoin(event:SFSEvent):void
    const room:Room = this._sfs.getRoomByName(PREGAME_ROOM);

    this.selectedChild = waitingRoom;

    /** I know I should be using event listeners
     *  but this is a temporary fix, otherwise
     *  I keep getting null object errors
     *  do to the li_users list not being
     *  created in time for the dataProvider assignment **/
    setTimeout(function ():void {
        const userList:ArrayList = new ArrayList(room.userList);
        this.li_users.dataProvider = userList;  // This is where the error gets thrown

My MXML Code:

    <mx:ViewStack xmlns:fx="http://ns.adobe.com/mxml/2009" 

        <fx:Script source="PreGame.as"/>

        <s:NavigatorContent id="nc_loginScreen">

            /** Login Screen Code **/


        /** Start of Waiting Room code **/
        <s:NavigatorContent id="waitingRoom">
            <s:Panel id="pn_users"
                     width="400" height="400"

                /** This is the List in question **/
                <s:List id="li_users"


However, I keep getting this error:


Any ideas what I'm doing wrong? The arrayList has data, so I know it's not empty/null.

share|improve this question
Is your 'this' pointer valid inside the timer function? –  ethrbunny Nov 10 '12 at 13:25
Wow, that did it! I figured since it was anonymous function it had access to all the data in it's parent function...oops! But I'd really like to scope out all my variables so how would I scope the List component since I can't use the "this" keyword? –  user1814467 Nov 10 '12 at 13:46
see my answer regarding timing and this scope issue –  Jason Reeves Nov 10 '12 at 22:55

1 Answer 1

Use data binding to solve the timing problem:

<s:List id="li_users" dataProvider="{users}" width="100%" height="100%"/>

Then in your script:

public var users:ArrayList;

private function onRoomJoin(event:SFSEvent):void
    public room:Room = this._sfs.getRoomByName(PREGAME_ROOM);
    this.selectedChild = waitingRoom;
    users = new ArrayList(room.userList);
share|improve this answer
Yeah, I know data binding would work, but in this scenario I want to avoid it if I can...is there a way instead to "force" the secondary NavigationContent area to generate itself before it is called? –  user1814467 Nov 11 '12 at 11:18
Dont know why you wouldn't want to use a data binding, but I guess you can add a creationComplete="listReady()" on your li_users. Then in listReady() say li_user.dataProvider=new ArrayList(room.userList). –  Jason Reeves Nov 11 '12 at 17:18
did this answer your question? Going through and checking answers to see how you faired? –  Jason Reeves Nov 28 '12 at 6:31

Your Answer


