I'll probably get this working by just changing things until it runs,
however, I'd like to really understand what is going wrong. ;)
My packaged class is below (at the bottom). IF I run it as the only file
in an actionscript project (in the Flex 3 ide). It works and draws 3 shapes
onto the screen.
However, if I try to call it from the default application class like this
(immediately below) I get nothing on the screen and I dont get any errors (I
didnt know wether I was supposed to use MovieClip or Sprite either).
----------------
package{
import flash.display.MovieClip;
import flash.display.Sprite;
import com.bueche.flex.graphics.BasicShapes;
public class MoveShapes extends Sprite{
public function MoveShapes (){
var testItem:BasicShapes = new BasicShapes();
}
} //end of class MoveShapes
} // end of package
-----------------------------
*********packaged class source****************************
package com.bueche.flex.graphics
{
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.JointStyle;
import flash.display.LineScaleMode;
import flash.display.Shape;
import flash.display.Sprite;
public class BasicShapes extends Sprite {
private var size:uint = 80;
private var bgColor:uint = 0xFFCC00;
private var borderColor:uint = 0x666666;
private var borderSize:uint = 0;
private var cornerRadius:uint = 9;
private var gutter:uint = 5;
public function BasicShapes() {
doDrawCircle();
doDrawRoundRect();
doDrawRect();
refreshLayout();
}
private function refreshLayout():void {
var ln:uint = numChildren;
var child:DisplayObject;
var lastChild:DisplayObject = getChildAt(0);
lastChild.x = gutter;
lastChild.y = gutter;
for (var i:uint = 1; i < ln; i++) {
child = getChildAt(i);
child.x = gutter + lastChild.x + lastChild.width;
child.y = gutter;
lastChild = child;
}//end of for
}//end of function
private function doDrawCircle():void {
var child:Shape = new Shape();
var halfSize:uint = Math.round(size/2);
child.graphics.beginFill(bgColor);
child.graphics.lineStyle(borderSize, borderColor);
child.graphics.drawCircle(halfSize, halfSize, halfSize);
child.graphics.endFill();
addChild(child);
}
private function doDrawRoundRect():void {
var child:Shape = new Shape();
child.graphics.beginFill(bgColor);
child.graphics.lineStyle(borderSize, borderColor);
child.graphics.drawRoundRect(0, 0, size, size, cornerRadius);
child.graphics.endFill();
addChild(child);
}
private function doDrawRect():void {
var child:Shape = new Shape();
child.graphics.beginFill(bgColor);
child.graphics.lineStyle(borderSize, borderColor);
child.graphics.drawRect(0, 0, size, size);
child.graphics.endFill();
addChild(child);
}
}//end of class BasicShapes
}//end of package