开发者

actiuon script 3 default constructor explanation

i get a duplicate declaration for these constructors, do the default constructor gets class as default.... some one knows the answer?

public function GraphNodeStyle() {
    super(CollapsibleNodeStyleComponent);
}

public function Gr开发者_开发技巧aphNodeStyle(componentClass:Class) {
    super(componentClass);
}


You can only have one constructor in ActionScript. Use an initializeWithComponentClass() method instead.


You can use a default value for your constructor and depends on the value call the super with the right parameter:

If you are interesting in differentiate new GraphNodeStyle(null) than new GraphNodeStyle() :

class GraphNodeStyle extends ... {
    function GraphNodeStyle(componentClass:Class=null) {
        super((componentClass===null)?CollapsibleNodeStyleComponent:componentClass);
    }
}

otherwise you can use * as type to accept undefined value so ou can differentiate both case, of course you loose the type verifying from the compiler since you accept any value and not only Classes :

class GraphNodeStyle extends ... {

    function GraphNodeStyle(componentClass:*=undefined) {
        super((componentClass===undefined)?CollapsibleNodeStyleComponent:componentClass);
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜