Get "term is undefined” error when trying to assign arrayList to List component dataSource

Posted by user1814467 on Stack Overflow See other posts from Stack Overflow or by user1814467
Published on 2012-11-10T13:21:08Z Indexed on 2012/11/10 23:00 UTC
Read the original article Hit count: 454

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
    },1000);
}

My MXML Code:

<?xml version="1.0" encoding="utf-8"?>
    <mx:ViewStack xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx"
        initialize="preGame_initializeHandler(event)"
        >

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

        <s:NavigatorContent id="nc_loginScreen">

            /** Login Screen Code **/

        </s:NavigatorContent>

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

                /** This is the List in question **/
                <s:List id="li_users"
                        width="100%" height="100%"/>

            </s:Panel>
        </s:NavigatorContent>
    </mx:ViewStack>

However, I keep getting this error:

TypeError: Error #1010: A term is undefined and has no properties

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

© Stack Overflow or respective owner

Related posts about flex

Related posts about actionscript