加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flash – ActionScript-3不能有多个构造函数?

发布时间:2020-12-15 19:50:33 所属栏目:百科 来源:网络整理
导读:我有 public function Shard() { } public function Shard(x:Number,y:Number,vx:Number,vy:Number,rotation:Number,spin:Number) { ... } 我得到了第二个构造函数: Multiple constructor definitions found. Constructor may not be defined in code. 因此
我有

public function Shard() {
    }

    public function Shard(x:Number,y:Number,vx:Number,vy:Number,rotation:Number,spin:Number)
    {
      ...
    }

我得到了第二个构造函数:

Multiple constructor definitions
found. Constructor may not be defined
in
code.

因此,ActionScript-3不能有多个构造函数?

解决方法

不,你不能有多个contructor,不同的函数与不同的签名,但你可以使用默认参数:

public function Shard(x:Number=NaN,y:Number=NaN) {
  //...
}

那么你可以调用新的Shard()或新的Shard(100)或新的Shard(100,200)

或者也可以使用变量参数:

public function Shard(...args){
 if (args.length==0) {
   //...
 } else {
  //...
  var firstArg:Object=args[0];
  //...
 }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读