AS3的索引数组和关联数组
来源:互联网 发布:软件产品质量模型 编辑:程序博客网 时间:2024/05/22 19:17
AS3中有两种数组,一种是索引数组,另一种是关联数组。两者根据不同情况,使用会非常方便。
Array(索引数组):
索引值是整数。第一个元素为Array.[0],第二个元素为Array.[1]。可以在索引数组中存储数字、字符串、对象等各种类型,甚至是数组对象(多维数组)。注意,Array类允许创建关联数组,但是Array类中的方法无法适用于关联数组。
示例代码:
var oneArray:Array = new Array("a", "b", "c");var twoArray:Array = oneArray; // Both array variables refer to the same array.twoArray[0] = "z"; trace(oneArray); // Output: z,b,c.
Object(字符串关联数组):
索引值是字符串。关联数组是和值对应的无序集合。在AS3中有两种创建关联数组的类:Object和Dictionary。
示例代码:
var monitorInfo:Object = {type:"Flat Panel", resolution:"1600 x 1200"}; trace(monitorInfo["type"], monitorInfo["resolution"]); // output: Flat Panel 1600 x 1200
索引值是对象。
示例代码:
var groupMap:Dictionary = new Dictionary(); // objects to use as keys var spr1:Sprite = new Sprite(); var spr2:Sprite = new Sprite(); var spr3:Sprite = new Sprite(); // objects to use as values var groupA:Object = new Object(); var groupB:Object = new Object(); // Create new key-value pairs in dictionary. groupMap[spr1] = groupA; groupMap[spr2] = groupB; groupMap[spr3] = groupB; if (groupMap[spr1] == groupA) { trace("spr1 is in groupA"); } if (groupMap[spr2] == groupB) { trace("spr2 is in groupB"); } if (groupMap[spr3] == groupB) { trace("spr3 is in groupB"); }
使用键值遍历关联数组:
for (var key:Object in groupMap) { trace(key, groupMap[key]); } /* output: [object Sprite] [object Object] [object Sprite] [object Object] [object Sprite] [object Object] */
- AS3的索引数组和关联数组
- 关联数组和索引数组的异同
- 索引数组 和关联数组
- as3,Dictionary,关联数组
- as3,Dictionary,关联数组
- JS 索引数组、关联数组和静态数组、动态数组
- 索引数组、关联数组和静态数组、动态数组
- 索引数组、关联数组和静态数组、动态数组
- php数组中的索引数组和关联数组
- 关联数组转换索引数组
- AS3的Dictionary与关联数组Object的区别
- 索引数组和关联数组的key与常量的关系
- AS3的Objec类t与关联数组
- smarty的使用,使用数组,一维数组,二维数组,关联数组,索引数组
- shell的 关联数组 和 普通数组
- AS3.0 Object 作为关联数组
- PHP之数组索引,关联
- AS3数组
- Mongodb持久化--journal探究(一
- arm多核架构
- csapp2e 家庭作业 5.19
- java.util.ConcurrentModificationException
- 如何查看android设备的PID和VID
- AS3的索引数组和关联数组
- 软件集成策略——如何有效率地提升质量
- 回调函数必须进行实现
- codeforce小水题--A. Presents
- hdu - 4602 - Partition(快速幂)
- csapp2e 家庭作业 5.22
- iOS 用NSNumberFormatter进行数字的格式化
- Photoshop----图层混合模式详解
- 例9.3 有3个候选人,每个选民只能投票选一人,要求编一个统计选票的程序,先后输入被选人的名字,最后输出各人得票结果。