I've finally been getting around to re-writing all my ActionScript 2.0 classes in ActionScript 3.0. Since a lot of A.S. 3 is still a little foreign to me, I thought I'd start simple with re-creating my shape classes. First up, draw.Circle.
package com.mikethenderson.draw { import flash.display.Shape; public class Circle extends Shape { // set propertires private var _color:uint; private var _radius:Number; private var _stroke:Array; // constructor public function Circle( args:Object ) { // when circle is created, then pass the goods draw( args ); } // draws circle based on set vars private function draw( args:Object ):void { // set defualts if any parameters are missing _color = ( args.color != undefined ) ? args.color : 0x000000; _radius = ( args.radius != undefined ) ? args.radius : 25; _stroke = ( args.stroke != undefined ) ? args.stroke : [0, 0x000000, 0]; // draw circle graphics.lineStyle( _stroke[0], _stroke[1], _stroke[2], true ); graphics.beginFill( _color ); graphics.drawCircle( 0, 0, _radius ); graphics.endFill(); } } }
Then to call the class, simply make an instance like so:
import com.draw.Circle;
var myCircle:Circle = new Circle ( { color:0xFF0000, radius:30, stroke:[1, 0x000000, 1] } );
myCircle.x = 100;
myCircle.y = 100;
addChild( myCircle );
Leave a Reply