Draw a rectangle : Rectangle : Graphics Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Graphics » Rectangle »

 

Draw a rectangle


 

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


        try {
          drawRectangle(this, 100200);
          drawRectangle(this, 300400);
        }
        catch(errObject:Error) {
          this.graphics.clear(  );
          trace("An error occurred: " + errObject.message);
        }
    }
    private function drawRectangle(sprite:Sprite, nWidth:Number, nHeight:Number):void {
      if(isNaN(nWidth|| isNaN(nHeight)) {
        throw new Error("Invalid dimensions specified.");
      }
      sprite.graphics.lineStyle(101);
      sprite.graphics.lineTo(nWidth, 0);
      sprite.graphics.lineTo(nWidth, nHeight);
      sprite.graphics.lineTo(0, nHeight);
      sprite.graphics.lineTo(00);
    }
  }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Graphics
» Rectangle