0

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
2
  • Did you mean associative array? Commented Feb 15, 2010 at 7:56
  • no not really, i wanted to pass a unsigned array, (not bound to a variable name) to a function like this test(['key': 'val']); maybe thats the wrong name for it :) Commented Feb 15, 2010 at 11:38

2 Answers 2

3

Search the help for Dictionary and Object.

Sign up to request clarification or add additional context in comments.

4 Comments

hmmm i don't understand, an array is not an object. i know how to set keys for objects
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.
did you read my question? I'm searching for a way to create UNSIGNED arrays
I hear you, like the original poster mentioned, you want to use an Object in AS3. Syntax: {'key':'value'}
2

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"

3 Comments

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.
Minor edit for the "associative" array detail. Thanks for the advice!
Dot syntax just can't be used if you have spaces in the key name (as in "may day").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.