Introduction

You are currently browsing the weblog archives for October, 2003.

Archive for October, 2003

Friday, October 24th, 2003

Datastructures

cheap cialis pill certified cialis cheap viagra in canada cialis buy drug buy generic cialis viagra buy 25mg viagra cheap viagra without prescription buy cheapest viagra on line purchase viagra cialis 10mg buying generic viagra cialis pills viagra from india cheapest sildenafil citrate cheap cialis no rx viagra india cialis bangkok viagra for order buy sildenafil internet buy generic viagra online buying cialis online where to order cialis tablet cialis find cialis no prescription required viagra cheap drug order cialis cheap online online pharmacy cialis cialis no rx order generic cialis price of cialis viagra soft drug viagra cheap viagra from uk order cialis no prescription order cheap viagra viagra drug order cheap cialis cheap cialis pharmacy best price for viagra cheap viagra from usa cost cialis cialis overnight shipping cheapest generic cialis online generic viagra online online viagra viagra sales cheap cialis in canada compare cialis prices online cialis online drug viagra online purchase discount cialis without prescription no rx viagra cialis overnight viagra uk cialis order cheap cialis from usa buying cialis cialis overnight delivery cialis in bangkok buy and purchase sildenafil online impotence treatment cheap price viagra viagra sale cheap cialis tablet drug cialis generic cialis online cheap viagra pharmacy find discount cialis online viagra malaysia cialis without a prescription buy cialis online cheap viagra rx buy no rx viagra cialis 20mg viagra in malaysia discount viagra online buy sildenafil cheap buy viagra low price buy cialis cialis cheap price cialis cheap generic viagra cialis canada low cost viagra buy cheap viagra cialis vs viagra order cialis from us cialis tablets find no rx cialis buy generic cialis online buy viagra overnight delivery cheapest cialis price buy cheapest cialis on line order cialis in canada viagra tablet viagra no online prescription find cheap cialis online viagra price order viagra no prescription cheap generic cialis buy viagra online cheap cialis uk cialis without rx generic cialis cheap viagra vs cialis order cialis on internet viagra tablets viagra purchase impotence drugs buy cialis generic cialis tablet cialis cheapest price order viagra from canada viagra generic cheap viagra from canada order cialis compare viagra prices online find cheap cialis impotence cure pfizer viagra find discount cialis cheapest cialis buy cialis from india impotence buy cheapest viagra online cialis side effects viagra order discount cialis online cialis in malaysia cialis in uk viagra in uk cialis online without prescription cialis online pharmacy order viagra buy viagra online viagra side effects cialis sale discount cialis no rx cheapest viagra find cialis order cialis no rx buy cialis low price buy viagra cheap drug cialis online purchase order discount viagra online 50 mg viagra 100 mg viagra 10mg cialis cost of cialis cheapest cialis prices buy discount viagra online cialis sales 50mg viagra cialis price buy viagra on internet cialis pill cheapest cialis online purchase viagra overnight delivery cheap cialis from canada cheapest viagra price cialis 20 mg buy sildenafil low cost order viagra without prescription buy viagra lowest price no prescription cialis order viagra on internet discount cialis overnight delivery cialis cheap drug viagra approved viagra no rx required compare viagra prices no rx cialis cheap cialis on internet buy viagra from india buy discount cialis online viagra pharmacy online order viagra from us cialis free delivery cialis for order buy cialis from canada viagra without rx viagra online review 10 mg cialis cheap viagra no rx cheapest viagra prices viagra prices cialis pharmacy order no rx cialis buy cialis in us buy cialis no prescription required order cialis from canada lowest price cialis cheap cialis internet online pharmacy viagra cheapest generic cialis generic drugs cialis india find cialis without prescription best price cialis buy viagra without prescription cheap cialis in uk where to buy viagra 20 mg cialis cheap cialis from uk buy sildenafil canada cialis no rx required cialis in us buy cialis overnight delivery cialis cheap price order cheap viagra online 20mg cialis buy cheap viagra online viagra internet viagra without prescription free cialis buy cialis us cialis buy buy viagra in canada order viagra cheap online find viagra without prescription viagra pills cheap cialis no prescription viagra online without prescription order generic viagra cialis discount viagra cheapest price purchase viagra no rx viagra no rx viagra cheap discount viagra overnight delivery sale cialis cialis pharmacy online purchase cialis without prescription pharmacy online cialis medication discount viagra buy cheap cialis impotence medication viagra medication find cialis on internet impotence pills cialis prices discount viagra without prescription cialis online cheap cialis online review find cheap viagra online buy viagra us purchase cialis online certified viagra where to order viagra buy cheapest viagra buy cialis internet order cialis online buy sildenafil online buy cialis cheap cheap viagra purchase cialis find discount viagra buy cialis on internet cialis buy online buy sildenafil online without a prescription viagra buy online order cheap cialis online viagra information no prescription viagra cost of viagra buy cialis in canada buy cialis online buy viagra cheapest generic viagra cialis us cialis australia fda approved cialis lowest price for viagra viagra bangkok cialis prescription cialis cost buy no rx cialis buy viagra internet viagra discount order viagra overnight delivery generic cialis viagra australia 25 mg viagra order viagra online viagra overnight cialis rx order cialis in us order viagra no rx order discount cialis online viagra vendors order viagra in us buy sildenafil in uk viagra us buy generic viagra viagra canada viagra no prescription viagra cheap price cheap viagra tablet viagra free delivery overnight viagra purchase viagra online find cheap viagra cialis malaysia best price viagra cialis free sample find viagra on internet cialis generic buy sildenafil in canada order cialis no prescription required cheapest viagra online purchase cialis no rx viagra in us order discount cialis cheap viagra internet free viagra cialis approved best price for cialis cialis from india find no rx viagra generic viagra viagra from canada viagra online pharmacy buy viagra from canada cheapest generic viagra online buy cheapest cialis discount cialis viagra overnight delivery cialis without prescription 100mg viagra cialis in australia price of viagra order cialis overnight delivery cheap viagra in uk buying generic cialis viagra pill buy cialis on line low cost cialis find discount viagra online buying viagra cheap cialis overnight delivery pharmacy cialis cheap viagra pill viagra prescription find viagra online buy cialis lowest price discount viagra no rx online cialis viagra free sample cheap viagra in usa find viagra cheap viagra online buy viagra no rx generic viagra cheap buy cialis without prescription buy viagra in us cheap viagra overnight delivery cheap cialis in usa cheap cialis online viagra order no rx viagra viagra soft tab find cialis online lowest price viagra cialis drug cialis vendors viagra online stores erectile dysfunction order viagra in canada buy viagra on line viagra overnight shipping viagra online cheap lowest price for cialis approved viagra pharmacy cialis 10 mg cialis no online prescription cialis purchase cialis from canada order cialis without prescription viagra for sale viagra in australia approved cialis pharmacy buy viagra generic buy sildenafil in spain find viagra no prescription required cialis no prescription buy viagra from us order viagra no prescription required cost viagra purchase viagra without prescription buy cialis no rx cialis cheap cialis internet tablet viagra cheap viagra on internet viagra cost pharmacy viagra cialis soft tab cialis information buy cheap cialis internet purchase cialis overnight delivery cheap cialis without prescription buy viagra no prescription required compare cialis prices buy cheap cialis online overnight cialis where to buy cialis cheap cialis buy cheap viagra internet buy discount cialis viagra buy drug cheap viagra no prescription buy sildenafil citrate buying viagra online buy discount viagra fda approved viagra cialis online stores cheap cialis tablets buy cheapest cialis online cheap viagra tablets order discount viagra sale viagra viagra online cialis for sale cialis soft viagra pharmacy buy cialis from us viagra without a prescription viagra in bangkok

Inspired by a tutorial about datastructures on javarworld.com from Jeff Friesen (good tutorial, worth reading), I wrote this little piece of code.
It isn’t useful at all because flash already has an Array class. But I think it’s interesting to see how these things, I expected always as normal, really work.

What you need are 4 classes named: ArrayStack, Node, EmptyStackException, FullStackException and 1 interface class named: Stack.

The ArrayStack.as file must be in one folder together with the Node.as file. That folder must contain two other folders named: Exception and SuperClasses.
The Exception folder contains the EmptyStackException.as file and the FullStackException.as file.
The SuperClasses folder contains the Stack.as file.

interface SuperClasses.Stack{
        public function isEmpty():Boolean;
        public function peek():Node;
        public function push(anObject:Node):Void;
        public function pop():Node;
        public function shift():Node;
        public function unshift(aNode:Node):Void;
        public function getNodeByNumber(aNumber:Number):Node
}
class Node{
        public var name:String;
        public var next:Node;
        public var prev:Node;

        public function Node(aName:String){
                name = aName;
        }
}
import SuperClasses.*
import Exceptions.*

class ArrayStack implements Stack{
        private var numbersOfElements:Number = -1;
        private var maxElements:Number = -1;
        private var topForward:Node;
        private var topBackward:Node;

        public function ArrayStack(mElements:Number){
                maxElements = mElements;
        }
        public function isEmpty():Boolean{
                return numbersOfElements < 0;
        }
        public function peek():Node{
                if(numbersOfElements < 0){
                        throw new EmptyStackException();
                }
                return topBackward;
        }
        public function push(aNode:Node):Void{
                if(numbersOfElements >= maxElements){
                        throw new FullStackException();
                }
                if(numbersOfElements == -1){
                        topForward = aNode;
                } else {
                        aNode.next = null;
                        aNode.prev = topBackward;
                        topBackward.next = aNode;
                }
                topBackward = aNode;
                numbersOfElements++;
        }
        public function pop():Node{
                if(numbersOfElements < 0){
                        throw new EmptyStackException();
                }
                numbersOfElements–;
                var temp:Node = topBackward;
                topBackward = topBackward.prev;
                return temp;
        }
        public function unshift(aNode:Node):Void{
                if(numbersOfElements >= maxElements){
                        throw new FullStackException();
                }
                if(numbersOfElements == -1){
                        topBackward = aNode;
                } else {
                        aNode.next = topForward;
                        aNode.prev = null;
                        topForward.prev = aNode;
                }
                topForward = aNode;
                numbersOfElements++;
        }
        public function shift():Node{
                if(numbersOfElements < 0){
                        throw new EmptyStackException();
                }
                numbersOfElements–;
                var temp:Node = topForward;
                topForward = topForward.next;
                return temp;
        }
        public function getNodeByNumber(aNumber:Number):Node{
                if(numbersOfElements < 0){
                        throw new EmptyStackException();
                }
                if(maxElements < aNumber){
                        throw new Error(”The number passed as an argument is too big!“);
                }
                var i:Number = 0;
                var temp:Node = topForward;
                while(i++ < aNumber){
                        temp = temp.next;
                }
                return temp;
        }
}
class Exceptions.EmptyStackException extends Error{
        var message = “The stack is already empty!“;
}
class Exceptions.FullStackException extends Error{
        var message = “The stack is already full!“;
}

// usage:
var arr:ArrayStack = new ArrayStack(3);
arr.push(new Node(”A“));
arr.push(new Node(”B“));
arr.push(new Node(”C“));
arr.push(new Node(”D“));
// arr.push(new Node(”E”));
// This additional function call would end the script because of an error.
// The ArrayStack is full.

trace(”function: getNodeByNumber“);

trace(arr.getNodeByNumber(0).name);
trace(arr.getNodeByNumber(1).name);
trace(arr.getNodeByNumber(2).name);
trace(arr.getNodeByNumber(3).name);
// trace(arr.getNodeByNumber(4).name);
// This additional function call would force the script to stop.
// The number is bigger than the maxElements number.

trace(”——————————“);
trace(”function: pop“);

trace(arr.pop().name);
trace(arr.pop().name);
trace(arr.pop().name);
trace(arr.pop().name);

// trace(arr.pop());
// This additional function call would end the script because of an error.
// The ArrayStack is empty.

arr.unshift(new Node(”A“));
arr.unshift(new Node(”B“));
arr.unshift(new Node(”C“));

trace(”——————————“);
trace(”function: getNodeByNumber“);

trace(arr.getNodeByNumber(0).name);
trace(arr.getNodeByNumber(1).name);
trace(arr.getNodeByNumber(2).name);

trace(”——————————“);
trace(”function: shift“);

trace(arr.shift().name);
trace(arr.shift().name);
trace(arr.shift().name);
/*
output:
function: getNodeByNumber
A
B
C
D
——————————
function: pop
D
C
B
A
——————————
function: getNodeByNumber
C
B
A
——————————
function: shift
C
B
A
*/

That’s it.
btw. the links to the tutorial are:
http://www.javaworld.com/javaworld/jw-05-2003/jw-0502-java101.html?
and
http://www.javaworld.com/javaworld/jw-06-2003/jw-0613-java101.html?

Friday, October 10th, 2003

How to use the VisibleObject Class

We are going to create a simple Rectangle class. Our goal is it to draw a Rectangle on stage just by writing:

var myRect:Rectangle = new Rectangle();
myRect.create();

At first we create a new ActionScript file and save it as Rectangle.as. The VisibleObject class from the previous post must be in the same directory. Open the Rectangle.as file and copy the following code in it.

// create a Rectangle class and let it inherit from the VisibleObject class
class Rectangle extends VisibleObject{
        // define the width and height properties
        private var width:Number;
        private var height:Number;

        public function Rectangle(){
                // set the type of the VisibleObject
                type = “Rectangle“;
                // set the default width and height
                width = 100;
                height = 12;
        }
        // override the create method
        public function create():Void{
                // call the original create method
                super.create();
                // draw the rectangle
                draw();
        }
        public function draw():Void{
                mc.beginFill(0×000000, 100);
                mc.moveTo(0, 0);
                mc.lineTo(0, height);
                mc.lineTo(width, height);
                mc.lineTo(width, 0);
                mc.lineTo(0, 0);
                mc.endFill();
        }
        public function clear():Void{
                mc.clear();
        }

        // declare getters and setters
        public function setWidth(aWidth:Number):Void{
                width = aWidth;
        }
        public function getWidth():Number{
                return width;
        }
        public function setHeight(aHeight:Number):Void{
                height = aHeight;
        }
        public function getHeight():Number{
                return height;
        }
        public function getBoundingBox():Object{
                return {width:width, height:height};
        }
}

That’s it. To test whether it works or not create a new fla and write the following code in it.

var myRect:Rectangle = new Rectangle();
myRect.create(); 

trace(myRect.getMC());
trace(myRect.getWidth());
trace(myRect.getHeight());
trace(myRect.getXPosition());
trace(myRect.getYPosition());

// Output:
// _level0.Rectangle_0_mc
// 100
// 12
// 0
// 0

If you want to see a bigger and more advanced example click here to download the bunch of code.
Click here to see the class hierarchy.
The zip contains all files shown in the class hierarchy as well as a fla that shows how to use all this.

Thursday, October 9th, 2003

VisibleObject

A little but useful class I use in almost every project that needs visible Objects like MovieClips on stage e.g. in a GUI.

class VisibleObject{
        public var type:String;

        private var container_mc:MovieClip;
        private var mc:MovieClip;

        private var depth:Number;

        private var xPosition:Number;
        private var yPosition:Number;

        private function VisibleObject(){
                type = “VisibleObject“;

                container_mc = _root;

                depth = container_mc.getNextHighestDepth();

                xPosition = 0;
                yPosition = 0;
        }
        public function create():Void{
                mc = container_mc.createEmptyMovieClip(getMCName(), depth);
                mc.master = this;
                setPosition();
        }
        public function remove():Void{
                mc.removeMovieClip();
                delete this; // Does this really work?
        }
        public function draw():Void{
                throw new Error(”The draw function hasn’t been overwritten!“);
        }
        public function clear():Void{
                throw new Error(”The clear function hasn’t been overwritten!“);
        }
        /*public function reset():Void{
        throw new Error(”The reset function hasn’t been overwritten!”);
}*/
        public function getBoundingBox():Void{
                throw new Error(”The getBoundingBox function hasn’t been overwritten!“);
        }
        public function getWidth():Void{
                throw new Error(”The getWidth function hasn’t been overwritten!“);
        }
        public function getHeight():Void{
                throw new Error(”The getHeight function hasn’t been overwritten!“);
        }

        private function setPosition():Void{
                mc._x = xPosition;
                mc._y = yPosition;
        }
        private function getMCName():String{
                return type + “_” + depth + “_mc“;
        }

        public function getMC():MovieClip{
                return mc;
        }

        public function setContainer(aContainer:MovieClip):Void{
                container_mc = aContainer;
                depth = container_mc.getNextHighestDepth();
        }
        public function getContainer():MovieClip{
                return container_mc;
        }

        public function setXPosition(aXPosition:Number):Void{
                xPosition = aXPosition;
        }
        public function getXPosition():Number{
                return xPosition;
        }

        public function setYPosition(aYPosition:Number):Void{
                yPosition = aYPosition;
        }
        public function getYPosition():Number{
                return yPosition;
        }
}

If I want to create a visible Object on stage e.g. a button, I create a Button class and let it inherit from the VisibleObject class. Then I specify all the drawing informations etc. After that steps I’m able to create a visible Button on stage just by writing:

myButton:Button = new Button();
myButton.create();

I’ll upload a real life example where it comes in handy in a few days.