A simple Ellipse class : Ellipse « Graphics « Flash / Flex / ActionScript






A simple Ellipse class

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var e:Ellipse = new Ellipse (100, 200);  // draw(  ) invoked here
        e.setWidth(25);   // draw(  ) invoked again here
        e.setHeight(50);  // draw(  ) invoked again here

    }
  }
}


  class Ellipse extends flash.display.Shape {
    private var w:Number;
    private var h:Number;

    public function Ellipse (width:Number, height:Number) {
      w = width;
      h = height;
      draw(  );
    }

    public function setWidth (newWidth:Number):void {
      w = newWidth;
      draw(  );
    }
    public function getWidth (  ):Number {
      return w;
    }

    public function setHeight (newHeight:Number):void {
      h = newHeight;
      draw(  );
    }

    public function getHeight (  ):Number {
      return h;
    }

    private function draw (  ):void {
      graphics.lineStyle(1);
      graphics.beginFill(0xFFFFFF, 1);
      graphics.drawEllipse(0, 0, w, h);
    }
  }

        








Related examples in the same category