adobe flash cs3 error 1119:ball.vx显示为未定义属性

时间:2013-03-11 08:34:32

标签: actionscript-3 flash

这是我制作多个弹簧动画的代码。但是我收到了这个错误。 ball.vx和ball.vy显示为未定义的属性。

我试过Keith Peters的“基金会代码” ActionScript 3.0动画 让事情发生变化!“

有谁知道如何修复它?

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;
}
}
}

2 个答案:

答案 0 :(得分:0)

我想,你遇到了这个问题:

每个文件夹的

Foundation ActionScript 3.0 Animation Making Things Move!源代码都有Ball.as一些不同。 ch03,ch05 Ball.as没有属性vxvy。你应该导入ch06或上层文件夹Ball.as他们有一个vxvy,如下所示:

package {
    import flash.display.Sprite;

    public class Ball extends Sprite {
        public 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();
        }
    }
}

答案 1 :(得分:0)

你能告诉我们Ball课程吗?可能没有声明vx和vx。