开发者

Best practice for setting default parameters in a AS3 class?

quick question: Is there a better way to do this?

public class ribbon extends Sprite {
    private var fa开发者_如何转开发llAmount,taper;

    public function ribbon(FallAmount=50,Taper=0.2){
        fallAmount=FallAmount;
        taper=Taper;
    }


You initial variables should have a value like displayed below and explicit strong typing is a feature of AS3 of which should never been forgotten. But aside from that - pretty sound.

k - I didn't realise this'll be a final solution - so here's some edits

  • Class names are uppercase. This is the same as as3 native (e.g. Sprite) and it defines the use of it well:

    var ribbon:Ribbon = new Ribbon() //See how it flows well.

  • Internal private var's can have an underscore. this denotes whilst programming an internal variable and is good for others when you share your code.


public class Ribbon extends Sprite {
    private var _fallAmount:int = 50;
    private var _taper:Number = .2;

    public function Ribbon(fallAmount:int=50, taper:Number=0.2){
        this._fallAmount = fallAmount;
        this._taper = taper;
    }
}

Hope it helps buddy.


I'd be most inclined to do this like so:

public class Ribbon extends Sprite
{
    private var _fallAmount:int = 50;
    private var _taper:Number = 0.2;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜