热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

1136:参数数量不正确。预期为0.AS3FlashCs4-1136:Incorrectnumberofarguments.Expected0.‎AS3FlashCs4

Basicallyiamworkingthroughabookcalled..FoundationActionscript3.0Animation,makingthingsm

Basically i am working through a book called..Foundation Actionscript 3.0 Animation, making things move.

基本上我正在写一本名为“基础动作脚本3.0动画”的书,让事情发生变化。

i am now on Chapter 9 - collision detection. On two lines of my code i get the 1135 error, letting me know that i have an incorrect number of arguments. Can anybody help me out on why this may be?

我现在在第9章 - 碰撞检测。在我的代码的两行中,我得到了1135错误,让我知道我的参数数量不正确。任何人都可以帮我解释为什么会这样吗?

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    public class Bubbles extends Sprite
    {
        private var balls:Array;
        private var numBalls:Number = 10;
        private var centerBall:Ball;
        private var bounce:Number = -1;
        private var spring:Number = 0.2;

        public function Bubbles()
        {
            init();
        }

        private function init():void
        {
            balls = new Array();
            centerBall = new Ball(100, 0xcccccc);
            addChild(centerBall);
            centerBall.x = stage.stageWidth / 2;
            centerBall.y = stage.stageHeight / 2;
            for(var i:uint = 0; i  stage.stageWidth)
           {
               ball.x = stage.stageWidth - ball.radius;
               ball.vx *= bounce;
           }
           else if(ball.x - ball.radius <0)
           {
               ball.x = ball.radius;
               ball.vx *= bounce;
           }
           // Having Trouble Here:
           if(ball.y + ball.radius > stage.stageHeight)
           {
               ball.y = stage.stageHeight - ball.radius;
               ball.vy *= bounce;
           }
           else if(ball.y - ball.radius <0)
           {
               ball.y = ball.radius;
               ball.vy *= bounce;
           }
        }
    }
}

I have indicated the lines i am having trouble with.

我已经指出我遇到麻烦了。

1 个解决方案

#1


0  

The following lines are the culprits.

以下几行是罪魁祸首。

centerBall = new Ball(100, 0xcccccc);
var ball:Ball = new Ball(Math.random() * 40 + 5, Math.random() * 0xffffff);

You're trying to pass arguments to Ball's constructor that takes zero arguments. Change them to

你试图将参数传递给Ball的构造函数,该构造函数接受零参数。将它们更改为

centerBall = new Ball();
var ball:Ball = new Ball();

respectively and it'll work. If you really want to pass initialization details, create a Ball.as file and assign it to the movie clip on the stage. Now declare the constructor of Ball class to accept these two arguments and initialize the variables (radius and color) inside the constructor.

分别,它会工作。如果您确实想要传递初始化详细信息,请创建一个Ball.as文件并将其分配给舞台上的影片剪辑。现在声明Ball类的构造函数接受这两个参数并初始化构造函数内的变量(半径和颜色)。


Ball.as would look something like

Ball.as看起来像

package
{
  public class Ball extends MovieClip
  {
    public function Ball(r:Number, col:uint)
    {
      this.radius = r;
      this.color = col;
    }
  }
}

推荐阅读
author-avatar
Utopia
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有