views:

63

answers:

2

hey how to create unsigned arrays with keys in actionscript 3?

in php its simple:

 array('key' => 'val');

in ac3 you can create unsigned arrays like that:

 ['val']
 ['key': 'val'] // breaks
+3  A: 

Search the help for Dictionary and Object.

WayneH
+1 Adobe does an excellent job with their documentation.
Tyler Egeto
hmmm i don't understand, an array is not an object. i know how to set keys for objects
antpaw
Any array is an object. (through inheritance). Regardless the syntax is the same. obj['foo'] = 'bar'; You should use an Object in the case, not an array.
Tyler Egeto
did you read my question? I'm searching for a way to create UNSIGNED arrays
antpaw
I hear you, like the original poster mentioned, you want to use an Object in AS3. Syntax: {'key':'value'}
Tyler Egeto
What is an UNSIGNED array?
Jotham
+1  A: 

An Object instance, because it is a dynamic class, can contain dynamic properites which works as a sort of associative array.

var object:Object = new Object();
object["foo"] = "Pedro";
object["bar"] = "Juan";
object["may day"] = "Enrique";

trace(object["foo"]); //Pedro
trace(object["bar"]); //Juan
trace(object["may day"]); //Enrique

Notice that the use of [] with an object is actually a way to access and define properties named like the string passed:

trace(object.foo); //Pedro
trace(object.bar); //Juan
//And I don't know how to access "may day"
LopSae
Hm you should add precisions about dot syntax and use of { } probably. "Unsigned array", do you mean "Associative" maybe ? The term dictionary is quite misleading since could refer to the specific Dictionary Class. The comment related to the "I don't know" in the end is just confusing... Don't get me wrong, just guess it is important being specially careful to explain basics to beginners.
Theo.T
Minor edit for the "associative" array detail. Thanks for the advice!
LopSae
Dot syntax just can't be used if you have spaces in the key name (as in `"may day"`).
Amarghosh
oh well, finally i got it. thanks
antpaw