Constants as Function Argument Defaults

Actionscript:
  1. const RADIUS = 10;
  2. const COLOR = 0xCCCCCC;
  3.  
  4. function createCircle(xp:Number, yp:Number, radius:Number = RADIUS, col:uint = COLOR):void{
  5.     var c:Sprite = new Sprite();
  6.     c.graphics.beginFill(col);
  7.     c.graphics.drawCircle(xp, yp, radius);
  8.     addChild(c);
  9. }
  10.  
  11. // optional last 2 values are populated with const defaults
  12. createCircle(100,100);
  13. // optional color value is populated with default 0xCCCCCC;
  14. createCircle(200,100, 20);
  15. //
  16. createCircle(300,100, 50,0x0000FF);

This entry was posted in functions, variables and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*