0

Is there a way to make an array composed of "tags", so I can refer to them by their "name"?

So usually when I want to refer to a position in my array I would do something like:

MyArray:Array = new Array( ["Marco", 26, "Portugal" ] );
trace(MyArray[2]);
Output: "Portugal"

I want to use an array where the positions have diferent names. So I wanted to be something like:

MyArray:Array = new Array( ["Marco", 26, "Portugal" ] );
trace(MyArray[Country]);
Output: "Portugal"

I'm pretty sure "tag" or "name" of the array isnt the propper term to use, but I don't know the correct one, so excuse me on that. Its also probably a easy question, but something that I never needed to use untill now. I'm building a "Area" array with positions, heigths and widths of several movieclips on stage, so I could use some simplification of the array to avoid always using numbers.

Thank you.

4

2 に答える 2

4

クラスを使用するだけObjectで、as3で連想配列を使用する最も簡単な方法です。

var ob:Object = {
  name: "Marco",
  age: 26,
  country:"Portugal"
};

trace(ob.country);
//output: Portugal

詳細については、AdobeのWebサイトでこの記事を確認することをお勧めします。ActionScript3の基礎:連想配列、マップ、および辞書

于 2012-07-24T12:13:13.260 に答える
0

配列を使用しているようですが、すべての要素に名前を付ける方法はありません。

AS3の「マップ」データ構造体をお勧めします。</p>

var DC:Dictionary=new Dictionary;
DC["Country"] = "Portugal";
DC["name"] = "Marco";
...

これがお役に立てば幸いです。

于 2012-07-24T12:07:35.567 に答える