// ******************************************************** *****************************
// filename: stack.as
// Description: stack
// Author: AOL
// Last Modified: 14/10/2003
// ******************************************************** *****************************
Import net.flash8.ds.linkedList;
Class Net.Flash8.ds.stack
{
Private var stacklist: linkedlist;
// conncture
Public function stack ()
{
StackList = New LinkedList ("stack");
}
// Add Object to Stack
Public Function Push (Object: Object): Void
{
StackList.insertatfront (Object);
}
// Remove Object from stack
Public Function Pop (): Object
{
Return stacklist.removefromfront ();
}
// DETERMINE IF Stack IS EMPTY
Public function isempty (): boolean
{
Return stacklist.isempty ();
}
// Output Stack Contents
Public function print (): void
{
StackList.print ();
}
}
// End Class Stack
//SATCKTEST.FLA
Import net.flash8.ds.stack;
Import net.flash8.ds.emptyListerror;
Var stack = new stack ();
// Create Objects to store in the stack
Var Bool: boolean = true;
Var integer: Number = 12324;
Var string: String = "Hello";
Var movieclip: moviClip = New Moviecip ("Movie Clip");
// USE PUSH METHOD
STACK.PUSH (BOOL);
Stack.print ();
Stack.push (Integer);
Stack.print ();
STACK.PUSH (STRING);
Stack.print ();
Stack.push (movieclip);
Stack.print ();
// Remove items from stack
Try
{
Var removedObject: Object = null;
For (var i: number = 1; i <6; i )
{
REMOVEDOBJECT = stack.pop ();
TransoveDObject.toString () "Popped");
Stack.print ();
}
}
// catch exception if stack empty when item popped
Catch (EmptyListerror)
{
EmptyListerror.Messagetrace ();
}
Output outcome: / ======= Begin of the stack table =============================================================================================================================================================================================== ======= / / ======= begin of the stack table ================================== end of the stack table =========== /
/ ======= begin of the stack table =========== / Hello 12324 true / ======================= ==== /
/ ======= Begin of the stack table =========== / undefined hello 12324 true / ============================================== ===== /
Undefined popped / ======= begin of the stack table =========================================================================================================================================================== ====== /
Hello popped / ======= begin of the stack table ========================== end of the stack table ====== ===== /
12324 popped / ======= Begin of the stack table ================================================================================================================================================================= ==== / True Poppedempty Stackan EmptyListerror: The Stack is Empty