ActionScript 3 AS3中的AssociativeArray

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3中的AssociativeArray相关的知识,希望对你有一定的参考价值。

package {
	
	import flash.utils.Proxy;
	import flash.utils.flash_proxy;
	
	/**
	 * A sample associative array with a working
	 * length property.
	 */
	dynamic public class AssociativeArray extends Proxy {
		
		private var memberValueHash:Object = new Object();
		private var memberIndexHash:Object = new Object();
		private var memberNameArray:Array = new Array();
			
		public function get length():uint {
			return memberNameArray.length;
		}
		override flash_proxy function setProperty(name:*, value:*):void {
			if (name in memberValueHash == false) {
				var last:uint = memberNameArray.length;
				memberIndexHash[name] = last;
				memberNameArray[last] = name;
			}
			memberValueHash[name] = value;
		}
		override flash_proxy function getProperty(name:*):* {
			return memberValueHash[name];
		}
		override flash_proxy function callProperty(name:*, ...rest):* {
			if (memberValueHash[name] is Function){
				return memberValueHash[name].apply(null, arguments);
			}
			return null;
		}
		override flash_proxy function hasProperty(name:*):Boolean {
			return name in memberValueHash;
		}
		override flash_proxy function deleteProperty(name:*):Boolean {
			if (name in memberValueHash){
				var index:int = memberIndexHash[name];
				memberNameArray.splice(index, 1);
				var last:uint = memberNameArray.length;
				while(index < last){
					memberIndexHash[memberNameArray[index]]--;
					index++;
				}
				delete memberValueHash[name];
				delete memberIndexHash[name];
				return true;
			}
			return false;
		}
		override flash_proxy function nextNameIndex(index:int):int {
			return (index < memberNameArray.length) ? index + 1 : 0;
		}
		override flash_proxy function nextName(index:int):String {
			return memberNameArray[index - 1];
		}
		override flash_proxy function nextValue(index:int):* {
			return memberValueHash[memberNameArray[index - 1]];
		}
		override flash_proxy function getDescendants(name:*):* {
			return null;
		}
		override flash_proxy function isAttribute(name:*):Boolean {
			return false;
		}
	}
}

以上是关于ActionScript 3 AS3中的AssociativeArray的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 AS3中的模糊滤镜

ActionScript 3 跟踪AS3中的对象

ActionScript 3 检查AS3中的连接

ActionScript 3 Flex中的AS3 Sprites

ActionScript 3 AS3中的按钮模板类

如何解决 ActionScript 3 (AS3) 中的关闭问题