Overriding Only Some Default Parameters in ActionScript
Posted
by TheDarkIn1978
on Stack Overflow
See other posts from Stack Overflow
or by TheDarkIn1978
Published on 2010-04-04T22:48:42Z
Indexed on
2010/04/04
22:53 UTC
Read the original article
Hit count: 564
i have a function which has all optional arguments. is it possible to override a an argument of a function without supplying the first?
in the code below, i'd like to keep most of the default arguments for the drawSprite function, and only override the last argument, which is the sprite's color.
but how can i call the object? DrawSprite(0x00FF00) clearly will not work.
//Main Class
package
{
import DrawSprite;
import flash.display.Sprite;
public class Start extends Sprite
{
public function Start():void
{
var myRect:DrawSprite = new DrawSprite(0x00FF00)
addChild(myRect);
}
}
}
//Draw Sprite Class
package
{
import flash.display.Sprite;
import flash.display.Graphics;
public class DrawSprite extends Sprite
{
private static const DEFAULT_WIDTH:Number = 100;
private static const DEFAULT_HEIGHT:Number = 200;
private static const DEFAULT_COLOR:Number = 0x000000;
public function DrawSprite(spriteWidth:Number = DEFAULT_WIDTH, spriteHeight:Number = DEFAULT_HEIGHT, spriteColor:Number = DEFAULT_COLOR):void
{
graphics.beginFill(spriteColor, 1.0);
graphics.drawRect(0, 0, spriteWidth, spriteHeight);
graphics.endFill();
}
}
}
© Stack Overflow or respective owner