這裏是我的代碼,使多個春天的動畫。但我得到這個錯誤。 ball.vx和ball.vy顯示爲未定義的屬性。adobe flash cs3錯誤1119:ball.vx顯示爲未定義的屬性
我試過Keith Peters的這段代碼「Foundation ActionScript 3.0 Animation Making Things Move!」
有誰知道如何解決它?
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Chain extends Sprite
{
private var ball0:Ball;
private var ball1:Ball;
private var ball2:Ball;
private var vx:Number = 0;
private var vy:Number = 0;
private var spring:Number = 0.1;
private var friction:Number = 0.8;
private var gravity:Number = 5;
public function Chain()
{
init();
}
private function init():void
{
ball0 = new Ball(20);
addChild(ball0);
ball1 = new Ball(20);
addChild(ball1);
ball2 = new Ball(20);
addChild(ball2);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
moveBall(ball0, mouseX, mouseY);
moveBall(ball1, ball0.x, ball0.y);
moveBall(ball2, ball1.x, ball1.y);
graphics.clear();
graphics.lineStyle(1);
graphics.moveTo(mouseX, mouseY);
graphics.lineTo(ball0.x, ball0.y);
graphics.lineTo(ball1.x, ball1.y);
graphics.lineTo(ball2.x, ball2.y);
}
private function moveBall(ball:Ball,
targetX:Number,
targetY:Number):void
{
ball.vx += (targetX - ball.x) * spring;
ball.vy += (targetY - ball.y) * spring;
ball.vy += gravity;
ball.vx *= friction;
ball.vy *= friction;
ball.x += ball.vx;
ball.y += ball.vy;
}
}
}
非常感謝您的小小的寶貴支持。我浪費時間,但卻發現問題在哪裏。另一方面,我不能繼續離開這個。最好的祝願。 :)(布魯斯) – user2151000 2013-03-12 12:05:11