基本上我正在通過一本叫做..Foundation Actionscript 3.0動畫的書,讓事情移動。1136:參數數量不正確。預計0. AS3 Flash Cs4
我現在在第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 < numBalls; i++)
{
var ball:Ball = new Ball(Math.random() *
40 + 5,
Math.random() * 0xffffff);
ball.x = Math.random() * stage.stageWidth;
ball.y = Math.random() * stage.stageHeight;
ball.vx = Math.random() * 6 - 3;
ball.vy = Math.random() * 6 - 3;
addChild(ball);
balls.push(ball);
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
for(var i:uint = 0; i < numBalls; i++)
{
var ball:Ball = balls[i];
move(ball);
var dx:Number = ball.x - centerBall.x;
var dy:Number = ball.y - centerBall.y;
var dist:Number = Math.sqrt(dx * dx + dy * dy);
var minDist:Number = ball.radius + centerBall.radius;
if(dist < minDist)
{
var angle:Number = Math.atan2(dy, dx);
var tx:Number = centerBall.x +
Math.cos(angle) * minDist;
var ty:Number = centerBall.y +
Math.sin(angle) * minDist;
ball.vx += (tx - ball.x) * spring;
ball.vy += (ty - ball.y) * spring;
}
}
}
// Having Trouble Here:
private function move(ball:Ball):void
{
ball.x += ball.vx;
ball.y += ball.vy;
if(ball.x + ball.radius > 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;
}
}
}
}
我已經指出了我遇到的問題。
當我創建了自己的球類來測試一下上面的代碼,它不拋出任何編譯錯誤。上面的星號線似乎也不是我可能的錯誤來源。也許你可能想編輯你的問題並添加Ball類的代碼? – anonymous 2010-05-17 01:39:39
同意。編譯器可能會抱怨這些行,但麻煩的原因是其他地方.. – fenomas 2010-05-17 01:45:07
我敢打賭,「球」的構造函數沒有任何參數。 – Amarghosh 2010-05-17 06:44:25