• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1341
  • Last Modified:

flex as3 associative array question

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
room[roomName].addObject(user);
This is a mix of associative array with some function as arrayCollection

Any help on how to achieve this ?
0
yarek
Asked:
yarek
1 Solution
 
evcrCommented:

You want to put objects in an associative array?

http://livedocs.adobe.com/flex/3/html/10_Lists_of_data_4.html#119542

Alternatively a multidimensional array might achieve what you want:
http://livedocs.adobe.com/flex/3/html/10_Lists_of_data_5.html#119820

0
 
madhupanisettyCommented:
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

0
 
yyyannagCommented:
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

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now