Introduction

Flash is a lightweight cross-platform runtime for rich media, enterprise applications and mobile applications, as well as an integrated development environment. Flash can be programmed in ActionScript 1/2/3.

Friday, November 28th, 2003 at 5:42 pm

The basic drawingAPI classes

These are the basic classes the drawingAPI uses. The must be in a folder called drawingAPI.
For all these who are new on this blog. These classes only work with the VisibleObject-Class. To get an idea what I’m talking about go a few steps backwards to the VisibleObject-entries.
Ok back to the topic. Here the classes.

The Shape-Class:

import asset.ShapeProperties;

class drawingAPI.Shape extends Graphic{
        public var type:String = “Shape“;

        public var border:Boolean;
        public var fill:Boolean;

        public var addBorder:Function;
        public var removeBorder:Function;

        public var addFill:Function;
        public var removeFill:Function;

        public var getPointByNumber:Function;
        public var getPointsTotal:Function;

        private var properties:ShapeProperties;

        public function Shape(Void){
                properties = new ShapeProperties(true, true);
        }
}

The ShapeComposite-Class:

import drawingAPI.Shape;
import drawingAPI.Border;
import drawingAPI.Fill;

class drawingAPI.ShapeComposite extends Shape/*, Picture*/{// [multiple inheritance]
        public var type:String = “ShapeComposite“;

        public var composite:Picture;

        public function ShapeComposite(Void){
                composite = new Picture();
        }
        public function draw(Void):Void{
                composite.draw();
                resize();
        }
        public function clear(Void):Void{
                var i:Number = 0;
                var shape:Shape;
                while(i < composite.getGraphicsTotal()){
                        shape = composite.getGraphicByNumber(i);
                        shape.clear();
                        i++;
                }
        }
        public function resize(Void):Void{
                mc._width = size.width;
                mc._height = size.height;
        }

        public function set width(aWidth:Number):Void{
                size.width = aWidth;
        }
        public function get width():Number{
                return size.width;
        }
        public function set height(aHeight:Number):Void{
                size.height = aHeight;
        }
        public function get height():Number{
                return size.height;
        }

        public function setSize(aWidth:Number, aHeight:Number):Void{
                size.width = aWidth;
                size.height = aHeight;
        }
        public function getSize(Void):Object{
                return size;
        }

        public function set fill(aBoolean:Boolean):Void{
                var i:Number = 0;
                var shape:Shape;
                while(i < composite.getGraphicsTotal()){
                        shape = composite.getGraphicByNumber(i);
                        shape.fill = aBoolean;
                        i++;
                }
                properties.fill = aBoolean;
        }
        public function get fill():Boolean{
                return properties.fill;
        }

        public function set border(aBoolean:Boolean):Void{
                var i:Number = 0;
                var shape:Shape;
                while(i < composite.getGraphicsTotal()){
                        shape = composite.getGraphicByNumber(i);
                        shape.border = aBoolean;
                        i++;
                }
                properties.border = aBoolean;
        }
        public function get border():Boolean{
                return properties.border;
        }

        public function addShape(aChild:Shape):Number{
                return composite.addGraphic(aChild);
        }
        public function removeShape(aChild:Shape):Void{
                composite.removeGraphic(aChild);
        }
        public function removeShapeByNumber(aNumber:Number):Void{
                composite.removeGraphicByNumber(aNumber);
        }
        public function getShapeByNumber(aNumber:Number)/*:Shape*/{// [type mismatch]
                return composite.getGraphicByNumber(aNumber);
        }
        public function getShapesTotal(Void):Number{
                return composite.getGraphicsTotal();
        }

        private function defineWidth(Void):Void{
                size.width = mc._width;
        }
        private function defineHeight(Void):Void{
                size.height = mc._height;
        }

        private function createMatrix(Void):Void{
                composite.setContainer(mc);
                composite.create();
        }
}

The GeometryShape-Class:

import drawingAPI.ShapeComposite;
import drawingAPI.Shape;
import drawingAPI.Border;
import drawingAPI.Fill;
import drawingAPI.GradientFill;
import asset.Point;

class drawingAPI.GeometryShape extends Shape{
        public var type:String = “GeometryShape“;

        private var points:Array;
        private var fillComposite:Picture;
        private var borderComposite:Picture;

        public function GeometryShape(Void){
                points = new Array();
                fillComposite = new Picture();
                borderComposite = new Picture();
        }
        public function draw(Void):Void{
                if(properties.fill) fillComposite.draw();
                else fillComposite.clear();
                if(properties.border) borderComposite.draw();
                else borderComposite.clear();
        }
        public function set fill(aBoolean:Boolean):Void{
                properties.fill = aBoolean;
        }
        public function get fill():Boolean{
                return properties.fill;
        }
        public function set border(aBoolean:Boolean):Void{
                properties.border = aBoolean;
        }
        public function get border():Boolean{
                return properties.border;
        }
        // border
        public function addBorder(aBorder:Border):Void{
                aBorder.master = this;
                borderComposite.addGraphic(aBorder);
        }
        public function removeBorder(aBorder:Border):Void{
                borderComposite.removeGraphic(aBorder);
        }
        // remark: fill and gradientFill should be handled all the same
        //         that means: you should be able to add a gradientFill or a normal fill with the addFill-method
        // fill
        public function addFill(aFill:Fill):Void{
                aFill.master = this;
                fillComposite.addGraphic(aFill);
        }
        public function removeFill(aFill:Fill):Void{
                fillComposite.removeGraphic(aFill);
        }
        // gradientFill
        public function addGradientFill(aGradientFill:GradientFill):Void{
                aGradientFill.master = this;
                fillComposite.addGraphic(aGradientFill);
        }
        public function removeGradientFill(aGradientFill:GradientFill):Void{
                fillComposite.removeGraphic(aGradientFill);
        }

        public function getPointsTotal(Void):Number{
                return points.length;
        }
        public function getPointByNumber(aNumber:Number):Point{
                return points[aNumber];
        }

        private function addPoint(aPoint:Point):Number{
                points.push(aPoint);
                return points.length-1;
        }

        private function createMatrix(Void):Void{
                fillComposite.setContainer(mc);
                fillComposite.create();

                borderComposite.setContainer(mc);
                borderComposite.create();
        }
}