- 浏览: 49638 次
- 性别:
- 来自: 上海
文章分类
// Arrays use numeric indexes:
var arr:Array = new Array();
arr[0] = "value";
// Generic objects use string indexes:
var obj:Object = new Object();
obj["key"] = "value";
// Dictionary uses object keys:
var dict:Dictionary = new Dictionary();
dict[myObj] = "value";
It’s important to understand that Dictionary uses strict equality to match the object, not the reference, as the key. This means that different references to the same object will act as the same key:
import flash.utils.Dictionary;
var a:Object = new Object();
var b:Object = a; // reference to the same object
var dict:Dictionary = new Dictionary();
dict[a] = "fun!";
trace(dict[b]); // traces 'fun!' because a===b
You can use any type of object as a key, not just generic objects (you could use a Sprite, or an Array, for example). This includes primitives (string, boolean, number, int, uint) which are matched based on value (again, strict equality):
var dict:Dictionary = new Dictionary();
dict["string"] = "joy!";
trace(dict["string"]); // traces "joy" because "string"==="string"
Dictionary objects are enumerable with “for in”, and “for each” loops:
for (var key:Object in dict) {
// iterates through each object key
}
for each (var value:Object in dict) {
// iterates through each value
}
You can also set a Dictionary to use weak references as keys. This is pretty cool, because it means that if you clear all references to an object except those in a weakly referenced dictionary, that object will be available for garbage collection, which in turn will release the reference to its value.
var a:Sprite = new Sprite();
// create a weakly referenced dictionary by passing true as first param:
var dict:Dictionary = new Dictionary(true);
dict[a] = new Object();
a = null; // clear original reference to the Sprite.
var arr:Array = new Array();
arr[0] = "value";
// Generic objects use string indexes:
var obj:Object = new Object();
obj["key"] = "value";
// Dictionary uses object keys:
var dict:Dictionary = new Dictionary();
dict[myObj] = "value";
It’s important to understand that Dictionary uses strict equality to match the object, not the reference, as the key. This means that different references to the same object will act as the same key:
import flash.utils.Dictionary;
var a:Object = new Object();
var b:Object = a; // reference to the same object
var dict:Dictionary = new Dictionary();
dict[a] = "fun!";
trace(dict[b]); // traces 'fun!' because a===b
You can use any type of object as a key, not just generic objects (you could use a Sprite, or an Array, for example). This includes primitives (string, boolean, number, int, uint) which are matched based on value (again, strict equality):
var dict:Dictionary = new Dictionary();
dict["string"] = "joy!";
trace(dict["string"]); // traces "joy" because "string"==="string"
Dictionary objects are enumerable with “for in”, and “for each” loops:
for (var key:Object in dict) {
// iterates through each object key
}
for each (var value:Object in dict) {
// iterates through each value
}
You can also set a Dictionary to use weak references as keys. This is pretty cool, because it means that if you clear all references to an object except those in a weakly referenced dictionary, that object will be available for garbage collection, which in turn will release the reference to its value.
var a:Sprite = new Sprite();
// create a weakly referenced dictionary by passing true as first param:
var dict:Dictionary = new Dictionary(true);
dict[a] = new Object();
a = null; // clear original reference to the Sprite.
发表评论
-
打开qq聊天面板
2012-07-18 00:40 0btn.addEventListener(MouseEvent ... -
帧播放完毕后 自动关闭 flash 播放器
2012-06-13 14:51 1008fscommand("quit", &qu ... -
as3 打开QQ聊天框
2012-04-10 03:03 923as3 打开QQ聊天框 作者:6dn 日期:2011-10- ... -
AS3动画效果公式,常用处理公式代码,基本运动公式,三角公式
2012-04-01 13:40 0as3种常见的弹性效果公式以及波形运动等as3动画效果公式代码 ... -
随机生成不同的数组
2012-03-29 15:14 836function RandomArray(n:int):Arr ... -
一些AS3中常用到的公式
2012-03-19 14:32 717基本三角函数的计算: 角的正弦值 = 对边 / 斜边 角的 ... -
图片循环滚动
2012-02-20 16:23 847//当第一张图片上移至看不到的位置时,删除该图片,并将该图片排 ... -
Flex代码格式化工具
2011-12-21 13:32 705Flex代码格式化工具 Flexformatter插件 安装与 ... -
字符串排序
2011-12-08 01:38 894var str1:String="很长很长的文本.. ... -
在AS3里..我们无法手动完全删除一个对象,,
2011-11-12 13:36 3347在AS3里..我们无法手动完全删除一个对象,, 以MovieC ... -
视 频
2011-11-09 21:16 664//创建一个 NetConnection 对象 002 var ... -
flashdevelop平台-搭建-配置
2011-11-09 20:43 636http://qilei.org/200810/flashde ... -
遍历 XML 结构
2011-11-09 20:23 612遍历 XML 结构 目录 [隐藏] 访问父节点和子节点 访 ... -
ActionScript 3.0基础提高——上篇
2011-11-07 22:52 598我一直非常重视ActionScri ... -
xml 格式
2011-11-07 22:50 637<?xml version="1.0" ... -
加载 xml 清除 空格什么的方法
2011-11-03 11:15 613var str2:String=str.replace(/\s ... -
AS3如何加载自身SWF
2011-11-01 13:26 772AS3如何加载自身SWF 分类: ActionScript3. ... -
加载很多图片
2011-10-24 00:41 577这几天做一个图片加载的程序,出现了点问题,主要是图片的 ... -
a.swf与加载的swf的通讯方法(as3.0)
2011-10-13 23:08 779a.swf加载b.swf, 在b.swf中使用a.swf的方法 ... -
MapDemo 人物移动(二)
2011-10-07 19:52 0上篇提到了人物的创建和人物行走的动画原理,这回我们看看人物的 ...
相关推荐
var obj3:Object = { name: "名字", age: 13, height: 170.5, say: function():void { trace("hello,world!"); } }; ``` 3. **动态属性和方法**:可以随时为Object添加属性和方法,如`obj4`和`obj5`的例子...
"iOS对象转字典 object2Dictionary"这个话题聚焦于如何将Objective-C或Swift中的对象转换成字典(NSDictionary或Swift的Dictionary类型),进而可能进一步转化为JSON格式。这种转换在序列化和反序列化过程中扮演着...
6. **哈希表(Hash Table)**:AS3的Object类实质上就是一个简单的哈希表,通过键值对快速查找和存取数据。如果需要更复杂、性能更高的哈希表,可以自定义数据结构,例如使用Dictionary类,它允许将任何类型作为键,...
3. `Dictionary` 不是序列化的,不能直接用于 XML 或 JSON 数据交换。 至于 `testAs2.as` 文件,虽然具体内容没有给出,但根据文件名猜测,它可能是一个 ActionScript 2.0 的源代码文件,用于测试 `contains` 方法...
此外,AS3的`SharedObject`可以用于本地数据缓存,虽然它更适合小规模的数据存储,而不是大资源的缓存。对于大资源的缓存,你可能需要自定义解决方案,比如使用内存对象池或者将资源分解成更小的部分来加载和缓存。 ...
Dim d As Object Set d = CreateObject("Scripting.Dictionary") ' 添加键值对 d.Add "a", "Athens" d.Add "b", "Belgrade" d.Add "c", "Cairo" ' 检查关键字是否存在 If d.Exists("c") Then MsgBox "指定的...
5. **数据持久化**:AS3CBLibrary可能包括本地存储解决方案,比如XML、JSON或SharedObject,便于在客户端保存用户数据。 6. **UI组件**:为了简化界面设计,库可能包含自定义的用户界面组件,如按钮、滑块、进度条...
在AS3中,一切皆为对象,所有的类都继承自Object类。基础数据类型如Number、Boolean、String等都是类,还有Array、Dictionary等复杂的数据结构。AS3的事件模型也更为成熟,通过Event类和EventListener接口处理程序中...
### AS3编码规范详解 ... - 不推荐使用`Object`作为`HashMap`,建议使用`Dictionary`替代。 通过上述规范的应用,开发者可以在实际项目开发过程中有效地提升代码的质量、可读性和可维护性,同时也能更好地协同工作。
字典是键值对的集合,与JavaScript的对象类似,但AS中的Dictionary允许非字符串作为键,提供了更灵活的数据存储。 9. 树(Tree) 树数据结构在AS中需要自定义实现,如二叉树或AVL树。树适用于需要快速查找、插入和...
2. **数据类型**:AS3支持基本数据类型如`Number`(浮点数和整数)、`String`、`Boolean`、`Object`等,以及复合数据类型如`Array`和`Dictionary`。 3. **函数定义**:函数在AS中用`function`关键字定义,例如`...
Dim d As New Dictionary Set d = CreateObject("scripting.Dictionary") d.Add "张三", "123" d.Add "李四", "456" '对象.新增 Key,Item '注意:在本地窗口中可能看不到Item条件。 'Keys方法 '返回一个数组,...
Static d As Object Static i As Long Dim iDup As Integer Dim sField ' ---------------------------------------- '这里填写需要检查的字段名 sField = [A] ' ---------------------------------------- If ...
ExtensionDictionary AS Autodesk.AutoCAD.DatabaseServices.ObjectId 可读不可写 FileName AS System.String 可读可写 FlagBits AS System.Byte 可读可写 Font AS Autodesk.AutoCAD.GraphicsInterface....
7. **数据类型和结构**:AS3支持基本数据类型(如Number, String, Boolean)以及复杂类型(如Array, Object, Dictionary)。还有强类型的数组类,如Array和Vector,其中Vector提供类型安全的数组操作。 8. **错误...
Dim dict As Object Set dict = CreateObject("Scripting.Dictionary") ``` 2. **添加元素**:使用`Add`方法向字典中添加键值对: ```vba dict.Add "key1", "value1" ``` 3. **访问和修改元素**:通过键来...
字典在AS3中是通过flash.utils.Dictionary类实现的,它提供了更高效的查找方式,尤其适合关联大量数据。 7. 集合(Set) 集合是一种不包含重复元素的数据结构,AS3中的flash.utils.Set类提供了这个功能。集合的元素...
关于java习惯的笔试题as2cs 将一些语法从 ActionScript 3 转换为 C# 再从 C# 转换回 ActionScript 3 的小例子。比较兼容的语法。...as2cs.py file.as ...as2cs.py ...Object 哈希转换为Dictionary<string, ob
3. **JSON转模型**:现在,你可以使用`NObject`的`object(from:)`方法将JSON字典转换为模型对象。 ```swift if let jsonString = "{\"name\":\"John\",\"age\":30,\"email\":\"john@example.com\"}".data(using: ....