0 Replies Latest reply on May 9, 2007 12:22 AM by theLoggerGuy

    Extending a class - help

    theLoggerGuy
      Hello all.

      I've just spend the better part of the afternoon making a 'arc' drawing routine seeing as Adobe didn't see fit to include on in their library. It works well when I place the code in line, but I would like to do something a little more reusable. So I was thinking that extending the UIComponent class would be the way to go (that way the line style, etc would be available to my variable), but when I create my class, nothings happens - no errors, but also nothing on the screen. The outline of my new class is as follows:
      package classes
      {
      import mx.core.UIComponent;

      public class MissingGraphics extends UIComponent
      {
      public function MissingGraphics()
      {
      super( );
      }

      public function drawArc( xCentre: Number, yCentre: Number, radius: Number, startAngleDeg: Number, StartAngleDeg: Number ): void
      {
      // the arc creation code goes here
      }
      }
      }


      Then in application:
      <mx:Script>
      <![CDATA[
      import classes.MissingGraphics;

      private var arc: MissingGraphics = new MissingGraphics;

      arc.graphics.lineStyle( 1 );
      arc.drawArc( xCentre, yCentre, radius, startAngleDeg );
      this.addChild( arc );
      ]]>

      What am I doing wrong?

      My arc drawing solution, in case anyone else would like the code, is as follows:
      private var arc: UIComponent = new UIComponent;

      private function drawArc( xCentre, yCentre, radius, startAngleDeg, finishAngleDeg ): void
      {
      // filthy geometry calculations - basically I use 8 curves to make an arc.
      var numberOfChords: int = 8;
      var angleStep: Number = ( finishAngleDeg - startAngleDeg ) / numberOfChords;
      var chordLength: Number = 2 * radius * Math.sin( ( angleStep / 2 ) * Math.PI / 180 );
      var d: Number = Math.sqrt( Math.pow( radius, 2 ) - Math.pow( chordLength / 2, 2 ) );
      var gap: Number = radius - d;
      var firstTime: Boolean = true;

      // set the line style
      face.graphics.lineStyle( 1 );

      // create a series of curves to make a complete arc.
      for ( var angle: Number = startAngleDeg; angle <= finishAngleDeg; angle += angleStep )
      {
      if ( true == firstTime )
      {
      arc.graphics.moveTo( xCentre + Math.sin( angle * Math.PI / 180 ) * radius,
      yCentre + Math.cos( angle * Math.PI / 180 ) * radius );

      firstTime = false;
      }
      else
      {
      arc.graphics.curveTo( xCentre + Math.sin( ( angle - angleStep / 2 ) * Math.PI / 180 ) * ( radius + gap ),
      yCentre + Math.cos( ( angle - angleStep / 2 ) * Math.PI / 180 ) * ( radius + gap ),
      xCentre + Math.sin( angle * Math.PI / 180 ) * radius,
      yCentre + Math.cos( angle * Math.PI / 180 ) * radius );
      }
      }

      // add the arc to the container
      this.addChild( arc );
      }