0

so I have an array with 4 string values in it (defined before array like public var p1:String etc)

public var partArray:Array = 
[
    p1 = ""
    p2 = ""
    p3 = ""
    p2_3 = ""
];

Lets say I have a textbutton with the name of one of these variables, how would I get the correct variable from the array using the name of the textbutton.

1 Answer 1

2

First of all, in AS3 it's not recomended to create associative arrays like this. For key:value maps use an Object (for example {key: "value"}) or a Dictionary.

With any container object you can lookup properties using array access brackets:

trace(myMap[key])

With an Array the key is an integer, with an Object the key is a string, and with a Dictionary the key is anything.

So to lookup a value by another object's name you might use:

myMap[myButton.name]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.