惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 叶小钗
MyScale Blog
MyScale Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
Martin Fowler
Martin Fowler
酷 壳 – CoolShell
酷 壳 – CoolShell
N
Netflix TechBlog - Medium
MongoDB | Blog
MongoDB | Blog
I
InfoQ
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security

博客园 - Morris

C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(673,5): error MSB3491: 未能向文件 - Morris as3 addEventListener各参数详解 在Flash中管理鼠标右键 Java与Action Script(Flash)类型对照 WinAPI--Win32 系统入口函数介绍 JavaScript 取得目前所在分割FRAME的寬度 用 FLASH CS5 作一個於 FLEX 可控制的 SWC 組件 Flash 創建好的 SWC 組件,如何在 FLEX 作一UI、簡單測試 Develop Android APP in Flash CS5 How to use Flex WebService Component in Flash Generate a iPhone certificate signing request on Windows 动态命名影片剪辑 訪問父MOVIECLIP下的所有依序列號命名的子MOVIECLIP - Morris - 博客园 心跳模拟 CodeSmith基础(一) - Morris - 博客园 AS2.0中实现数据结构-哈希表 Alcon 使用方式重點 Flash AS2 同 VB.NET 類似的 WITH 寫法 flash AS3应用程序模块化开发与ApplicationDomain
Associative arrays
Morris · 2010-12-13 · via 博客园 - Morris

The second way to create an associative array is to use the Array constructor (or the constructor of any dynamic class) and then use either the array access ( [] ) operator or the dot operator ( . ) to add key and value pairs to the array. If you declare your associative array to be of type Array, you cannot use an object literal to initialize the array. The following example creates an associative array named monitorInfo using the Array constructor and adds a key called type and a key called resolution , along with their values:

var monitorInfo:Array = new Array();
monitorInfo["type"] = "Flat Panel";
monitorInfo["resolution"] = "1600 x 1200";
trace(monitorInfo["type"], monitorInfo["resolution"]);
// output: Flat Panel 1600 x 1200

After the array is created using either an object literal or the Object class constructor, you can add new values to the array using either the array access ( [] ) operator or the dot operator ( . ). The following example adds two new values to monitorArray :

monitorInfo["aspect ratio"] = "16:10"; // bad form, do not use spaces
monitorInfo.colors = "16.7 million";
trace(monitorInfo["aspect ratio"], monitorInfo.colors);
// output: 16:10 16.7 million

The following code creates three instances of the Sprite class that serve as keys for the Dictionary object. Each key is assigned a value of either GroupA or GroupB . The values can be of any data type, but in this example both GroupA and GroupB are instances of the Object class. Subsequently, you can access the value associated with each key with the array access ( [] ) operator, as shown in the following code:

import flash.display.Sprite;
import flash.utils.Dictionary;

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");
}

If you use myObject as a key in a Dictionary object, you are creating another reference to the original object. For example, the following code creates two references to an objectthe myObject variable, and the key in the myMap object:

import flash.utils.Dictionary;

var myObject:Object = new Object();
var myMap:Dictionary = new Dictionary();
myMap[myObject] = "foo";

Alternatively, you can use the useWeakReference parameter of the Dictionary constructor to make all of the dictionary keys weak references . The garbage collection system ignores weak references, which means that an object that has only weak references is eligible for garbage collection. For example, in the following code, you do not need to delete the myObject key from myMap in order to make the object eligible for garbage collection:

import flash.utils.Dictionary;

var myObject:Object = new Object();
var myMap:Dictionary = new Dictionary(true);
myMap[myObject] = "foo";
myObject = null; // Make object eligible for garbage collection.