flex as3 associative array question

Posted on 2008-11-13
Last Modified: 2013-11-11
I am trying to do soemthing like

var roomName:String = "room1" ; // room name
var user:User = new User("john","male"'); // new user John, male
room[roomName].addObject(user); // add his to the room

But I do not know if this is possible to obtain that in AS3
This is a mix of associative array with some function as arrayCollection

Any help on how to achieve this ?
Question by:yarek
    LVL 7

    Expert Comment


    You want to put objects in an associative array?

    Alternatively a multidimensional array might achieve what you want:

    LVL 1

    Expert Comment

    use push instead of addObject
    Also create an array before using push
    var room:Array = new Array;
    var roomName:String = "room1" ; // room name
    room[roomName] = new Array;
    var Ouser1:user = new user("madhu",24); //user1
    var Ouser2:user = new user("john",26); //user2
    room[roomName].push (Ouser1);
    room[roomName].push (Ouser2);
    trace("[room]"+ room[roomName]);

    Open in new window

    LVL 2

    Accepted Solution

    You can always use Dictionary to act as associative arrays.

    var dict:Dictionary = new Dictionary;
    var roomName:String = "room1";
    var user1:user = new user("madhu",24);
    dict[roomName] = user1;
    trace("room: " + dict[roomName]);

    Open in new window


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Flash movie or gif/animation? 3 810
    How to convert pdf file to html file 8 362
    Video sharing with user login 3 181
    Flash Converter 8 97
    This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now