PDA

View Full Version : How do I make an associative/hash array?


Mike Barber
11-10-2004, 04:48 PM
I am sure there is a less tedious way than:


var myArray:Array = new Array();

myArray["id"] = id_txt.text;
myArray["user"] = username_txt.text;
myArray["email"] = email_txt.text;


In PHP I would do:

$myArray = array ("id" => $id_txt, "user" => $username_txt, "email" => $email_txt);


Is there not a similar way to do this in ActionScript?

senocular
11-10-2004, 04:53 PM
not if you want it to remain an array data type.

As a basic object (which array inherits) you can use:

myArray = {id: id_txt.text, user: username_txt.text, email: email_txt.text};

Note: dot syntaxt is also acceptable (to replace bracket)

myArray.id = id_txt.text;