ActionScript 3 AS3 | ArrayStack
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3 | ArrayStack相关的知识,希望对你有一定的参考价值。
package kc.tda {
import kc.api.IStack;
import kc.events.CollectionEvent;
[Event( name="addAll", type="kc.events.CollectionEvent" )]
[Event( name="clear", type="kc.events.CollectionEvent" )]
[Event( name="remove", type="kc.events.CollectionEvent" )]
[Event( name="removeAll", type="kc.events.CollectionEvent" )]
[Event( name="retain", type="kc.events.CollectionEvent" )]
[Event( name="push", type="kc.events.CollectionEvent" )]
[Event( name="pop", type="kc.events.CollectionEvent" )]
public class ArrayStack extends ArrayCollection implements IStack {
// @constructor
public function ArrayStack( capacity:int = undefined, expandableCapacity:Boolean = false, loadFactor:Number = NaN ) {
super( capacity, expandableCapacity, loadFactor );
_events = [
CollectionEvent.ADD_ALL,
CollectionEvent.CLEAR,
CollectionEvent.REMOVE,
CollectionEvent.REMOVE_ALL,
CollectionEvent.RETAIN,
CollectionEvent.PUSH,
CollectionEvent.POP
];
}
// @override
override public function add( value:* ):Boolean {
return push( value );
}
override public function remove( value:* ):Boolean {
return ( value != null )
? super.remove( value )
: ( pop() != null )
? true
: false;
}
// @methods
public function element():* {
ThrowIsEmpty();
return _records[0];
}
public function peek():* {
try{
var value:* = element();
}catch(e:Error){
return null;
} return value;
}
public function push( value:* ):Boolean {
if( ! ResolveStatus() ) {
return false;
}
var quantity:int = size();
_records.unshift( value );
if( size() != quantity ){
ResolveDispatchEvent( CollectionEvent.PUSH );
return true;
} return false;
}
public function pop():* {
var quantity:int = size();
var value:* = _records.shift();
if( size() != quantity ) {
ResolveDispatchEvent( CollectionEvent.POP );
return value;
} return null;
}
}
}
// @INTERFACE
package kc.api {
public interface IStack extends ICollection {
// @methods
function element():*;
function peek():*;
function push(value:*):Boolean;
function pop():*;
}
}
以上是关于ActionScript 3 AS3 | ArrayStack的主要内容,如果未能解决你的问题,请参考以下文章
[ActionScript 3.0] AS3.0 水面波纹效果
ActionScript 3 AS3:使用SWFObject2和AS3传递变量
ActionScript 3 克隆数组(AS3)
ActionScript 3 AS3序列化
ActionScript 3 As3初始上限
ActionScript 3 AS3 HTML清理