⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datalist.as

📁 用于flash/flex的 as3的 2D图形图像图表的动态生成
💻 AS
📖 第 1 页 / 共 2 页
字号:
		 */		
		public function visit(visitor:Function, filter:*=null,
			reverse:Boolean=false):Boolean
		{
			_visiting++; // mark a visit in process
			var a:Array = _list; // use our own reference to the list
			var i:uint, n:uint=a.length, b:Boolean = false;
			var f:Function = Filter.$(filter);
			
			if (reverse && f==null) {
				for (i=n; --i>=0;)
					if (visitor(a[i]) as Boolean) {
						b = true; break;
					}
			}
			else if (reverse) {
				for (i=n; --i>=0;)
					if (f(a[i]) && (visitor(a[i]) as Boolean)) {
						b = true; break;
					}
			}
			else if (f==null) {
				for (i=0; i<n; ++i)
					if (visitor(a[i]) as Boolean) {
						b = true; break;
					}
			}
			else {
				for (i=0; i<n; ++i)
					if (f(a[i]) && (visitor(a[i]) as Boolean)) {
						b = true; break;
					}
			}
			_visiting = Math.max(0, --_visiting); // unmark a visit in process
			return b;
		}
		
		// -- Default Values --------------------------------------------------
		
		/**
		 * Sets a default property value for newly created items.
		 * @param name the name of the property
		 * @param value the value of the property
		 */
		public function setDefault(name:String, value:*):void
		{
			if (_defs == null) _defs = {};
			_defs[name] = value;
		}
		
		/**
		 * Removes a default value for newly created items.
		 * @param name the name of the property
		 */
		public function removeDefault(name:String):void
		{
			if (_defs != null) delete _defs[name];
		}
		
		/**
		 * Sets default values for newly created items.
		 * @param values the default properties to set
		 */
		public function setDefaults(values:Object):void
		{
			if (_defs == null) _defs = {};
			for (var name:String in values)
				_defs[name] = values[name];
		}
		
		/**
		 * Clears all default value settings for this list.
		 */
		public function clearDefaults():void
		{
			_defs = null;
		}
		
		/**
		 * Applies the default values to an object.
		 * @param o the object on which to set the default values
		 * @param vals the set of default property values
		 */
		public function applyDefaults(o:Object):void
		{
			if (_defs == null) return;
			
			for (var name:String in _defs) {
				var value:* = _defs[name];
				if (value is IEvaluable) {
					value = IEvaluable(value).eval(o);
				} else if (value is Function) {
					value = (value as Function)(o);
				}
				Property.$(name).setValue(o, value);
			}
		}
		
		// -- Set Values ------------------------------------------------------
		
		/**
		 * Sets a property value on all items in the list. The value can take
		 *  a number of forms:
		 * <ul>
		 *  <li>If the value is a <code>Function</code>, it will be evaluated
		 *      for each element and the result will be used as the property
		 *      value for that element.</li>
		 *  <li>If the value is an <code>IEvaluable</code> instance, such as
		 *      <code>flare.util.Property</code> or
		 *      <code>flare.query.Expression</code>, it will be evaluated for
		 *      each element and the result will be used as the property value
		 *      for that element.</li>
		 *  <li>In all other cases, the property value will be treated as a
		 *      literal and assigned for all elements.</li>
		 * </ul>
		 * @param name the name of the property
		 * @param value the value of the property
		 * @param t a transitioner or time span for updating object values. If
		 *  the input is a transitioner, it will be used to store the updated
		 *  values. If the input is a number, a new Transitioner with duration
		 *  set to the input value will be used. The input is null by default,
		 *  in which case object values are updated immediately.
		 * @param filter an optional Boolean-valued filter function for
		 * 	limiting which items are visited
		 * @return the transitioner used to update the values
		 */
		public function setProperty(name:String, value:*, t:*=null,
			filter:*=null):Transitioner
		{
			var trans:Transitioner = Transitioner.instance(t);
			var f:Function = Filter.$(filter);
			Arrays.setProperty(_list, name, value, f, trans);
			return trans;
		}
		
		/**
		 * Sets property values on all sprites in a given group. The values
		 * within the <code>vals</code> argument can take a number of forms:
		 * <ul>
		 *  <li>If a value is a <code>Function</code>, it will be evaluated
		 *      for each element and the result will be used as the property
		 *      value for that element.</li>
		 *  <li>If a value is an <code>IEvaluable</code> instance, such as
		 *      <code>flare.util.Property</code> or
		 *      <code>flare.query.Expression</code>, it will be evaluated for
		 *      each element and the result will be used as the property value
		 *      for that element.</li>
		 *  <li>In all other cases, a property value will be treated as a
		 *      literal and assigned for all elements.</li>
		 * </ul>
		 * @param vals an object containing the properties and values to set.
		 * @param t a transitioner or time span for updating object values. If
		 *  the input is a transitioner, it will be used to store the updated
		 *  values. If the input is a number, a new Transitioner with duration
		 *  set to the input value will be used. The input is null by default,
		 *  in which case object values are updated immediately.
		 * @param filter an optional Boolean-valued filter function for
		 * 	limiting which items are visited
		 * @return the transitioner used to update the values
		 */
		public function setProperties(vals:Object, t:*=null,
			filter:*=null):Transitioner
		{
			var trans:Transitioner = Transitioner.instance(t);
			var f:Function = Filter.$(filter);
			for (var name:String in vals)
				Arrays.setProperty(_list, name, vals[name], f, trans);
			return trans;
		}
		
		/**
		 * A function generator that can be used to set properties
		 * at a later time. This method returns a function that can
		 * accept a <code>Transitioner</code> as its sole argument and then
		 * executes the <code>setProperties</code> method. 
		 * @param vals an object containing the properties and values to set.
		 *  This is treated the same as the <code>setProperties</code> method.
		 * @param filter an optional Boolean-valued filter function for
		 * 	limiting which items are visited
		 * @return a function that accepts a <code>Transitioner</code> argument
		 *  and runs <code>setProperties</code>.
		 */
		public function setLater(vals:Object, filter:*=null):Function
		{
			return function(t:Transitioner=null):Transitioner {
				return setProperties(vals, t, filter);
			}
		}
		
		
		// -- Statistics ------------------------------------------------------
				
		/**
		 * Computes and caches statistics for a data field. The resulting
		 * <code>Stats</code> object is cached, so that later access does not
		 * require any re-calculation. The cache of statistics objects may be
		 * cleared, however, if changes to the data set are made.
		 * @param field the property name
		 * @return a <code>Stats</code> object with the computed statistics
		 */
		public function stats(field:String):Stats
		{
			// TODO: allow custom comparators?
			
			// check cache for stats
			if (_stats[field] != undefined) {
				return _stats[field] as Stats;
			} else {
				return _stats[field] = new Stats(_list, field);
			}
		}
		
		
		/**
		 * Clears any cached stats for the given field. 
		 * @param field the data field to clear the stats for.
		 */
		public function clearStats(field:String):void
		{
			delete _stats[field];
		}
		
		
		// -- Event Dispatcher Methods ----------------------------------------
		
		/** @private */
		protected function fireEvent(type:String, items:*):Boolean
		{
			if (_dispatch.hasEventListener(type)) {
				return _dispatch.dispatchEvent(
					new DataEvent(type, items, this));
			}
			return true;
		}
		
		/** @inheritDoc */
		public function addEventListener(type:String, listener:Function,
			useCapture:Boolean=false, priority:int=0, 
			useWeakReference:Boolean=false) : void
		{
			_dispatch.addEventListener(type, listener, useCapture, priority,
				useWeakReference);
		}
		
		/** @inheritDoc */
		public function dispatchEvent(event:Event):Boolean
		{
			return _dispatch.dispatchEvent(event);
		}
		
		/** @inheritDoc */
		public function hasEventListener(type:String):Boolean
		{
			return _dispatch.hasEventListener(type);
		}
		
		/** @inheritDoc */
		public function removeEventListener(type:String, listener:Function,
			useCapture:Boolean=false):void
		{
			_dispatch.removeEventListener(type, listener, useCapture);
		}
		
		/** @inheritDoc */
		public function willTrigger(type:String):Boolean
		{
			return _dispatch.willTrigger(type);
		}
		
		// -- Proxy Methods ---------------------------------------------------
		
		/** @private */
		flash_proxy override function getProperty(name:*):*
		{
        	return _list[name];
    	}
    	
    	/** @private */
    	flash_proxy override function setProperty(name:*, value:*):void
    	{
    		this.setProperty(name, value);
    	}
		
		/** @private */
		flash_proxy override function nextNameIndex(idx:int):int
		{
			return (idx < _list.length ? idx + 1 : 0);
		}

		/** @private */
		flash_proxy override function nextName(idx:int):String
		{
			return String(idx-1);
		}
		
		/** @private */
		flash_proxy override function nextValue(idx:int):*
		{
			return _list[idx-1];
		}
		
	} // end of class DataList
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -