(我以前也問過這個,但我不認爲我很直接的與我的問題,因此沒有得到所以在這裏再次得到解決去!)1136:參數數量不正確。預計0 AS3的Flash Cs4的(第2輪)
我的工作通過一本名爲的Foundation Actionscript 3.0動畫,使事物移動。
我現在在第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;
}
}
}
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;
}
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.as
的非所有腦幹,閱讀教程時,我認爲這意味着我必須創建一個影片剪輯然後將其導出爲類別名爲Ball的動作,但是當通過該書輕彈時,我看到已經存在一個Ball.as
,指出我可能需要稍後在本書中再次使用它,這個閱讀:
package
{
import flash.display.Sprite;
public class Ball extends Sprite
{
private var radius:Number;
private var color:uint;
public var vx:Number=0;
public var vy:Number=0;
public function Ball(radius:Number=40, color:uint=0xff0000)
{
this.radius=radius;
this.color=color; init();
}
public function init():void
{
graphics.beginFill(color);
graphics.drawCircle(0, 0, radius);
graphics.endFill();
}
}
}
設法阻止所有出現的錯誤,但它沒有傳送任何它的效果來自Bubbles.as
,它只是在舞臺中央抱着一個紅球。我如何改變這段代碼才能支持Bubbles.as?
請幫忙!謝謝!
哦,我的falomir,你真的幫助我,非常感謝你,如果我問你最後一個問題,這是粗魯嗎?你有它的工作權利?所以你知道它是什麼樣子,反正我可以讓中間的靜態球跟着鼠標移動? – charmaine 2010-05-20 00:57:58