adobe flash cs3错误1119:ball.vx显示为未定义的属性
问题描述:
这里是我的代码,使多个春天的动画。但我得到这个错误。 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;
}
}
}
答
我猜,你面临这样的问题:
Foundation ActionScript 3.0 Animation Making Things Move!源代码的每个文件夹有Ball.as
一些不同。 ch03,ch05 Ball.as
没有房产vx
,vy
。你应该导入CH06或上一级文件夹Ball.as
他们有一个vx
,vy
如下:
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();
}
}
}
答
,你能否告诉我们球类?可能vx和vx没有声明。
+0
我使用ball.as从章节没有包括vx和vy属性。现在我得到了解决方案。感谢您的支持。 – user2151000 2013-03-12 12:02:16
非常感谢您的小小的宝贵支持。我浪费时间,但却发现问题在哪里。另一方面,我不能继续离开这个。最好的祝愿。 :)(布鲁斯) – user2151000 2013-03-12 12:05:11