你好,我这里有一个泡泡游戏的动作脚本代码。当游戏开始时,气泡从游戏的顶部掉到底部,并为30秒内点击或弹出的最多气泡保留分数。
气泡的大小由代码中的initialize方法定义,并使用ToString()计算分数。ToString通过具有静态类型uint的引用,为我提供了一个对可能未定义的方法Random的1061:调用。我不知道这个错误是从哪里来的。
如果任何有AS3经验的人能给我一些关于我缺点的建议,我将不胜感激。谢谢。
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.media.Sound;
public class Ball extends MovieClip{
static public var burstCounter: uint;
private var vx: Number;
private var vy: Number;
private var gravity: Number;
private var stageWidth;
private var stageHeight;
private var bubble:Ball = new Ball();
private var score: uint=0;
public function Ball() {
bubble.addEventListener(Event.ADDED_TO_STAGE, initialize)
bubble.addEventListener(MouseEvent.CLICK, burst)
bubble.addEventListener(Event.ENTER_FRAME, dropping)
}
public function initialize (e:Event):void
{
bubble.x = Math.random() * stageWidth;
bubble.y = 0;
stageWidth = stage.stageWidth;
stageHeight = stage.stageHeight;
bubble.vx = Math.random() * 2 - 1;
bubble.vy = Math.random() * 2 + 1;
gravity = 0.1;
var sizeScale = Math.random() * 1.2 + .6;
bubble.scaleX = bubble.scaleY = sizeScale;
score = (10 / sizeScale);
scoreValue.text = score.ToString();
var colorTran = new ColorTransform();
colorTran.color = Math.random() * 0xFFFFFF;
transform.colorTransform = colorTran;
addChild(bubble);
}
function dropping(e: Event) :void
{
x += vx;
y += vy;
vy += gravity;
if((x<0) || (x>stageWidth) || (y<0) || (y>stageHeight))
{
if(parent != null)
{
parent.removeChild(this);
}
removeEventListener(Event.ENTER_FRAME, dropping)
}
}
function burst (e:Event):void
{
var ballonPopping: Sound = new BalloonPopping();
bubble.removeEventListener(Event.ADDED_TO_STAGE, initialize);
bubble.removeEventListener(Event.ENTER_FRAME, dropping);
removeChild(bubble);
ballonPopping.play();
burstCounter += score;
}
}
}
请改用Math.random()
。。。
您需要更改的每次出现
Math.Random()
至
Math.random()
注意小写r
或者。。。因为看起来你刚刚为ToString()编辑了这个问题
尝试
toString()
请注意这些错误有多么相似。您正在绑定调用一个在这两个方法中都不存在的方法。资本化问题VAR与VAR 不同
uint
也没有ToString()方法,但它有一个ToString()。
大小写在方法名称中很重要。:)
在命名&调用属性或方法。
ActionScript的成员使用pascalCasing
,包括static
。常量使用ALL_CAPS
。
我想不出ActionScript中有任何类成员像您一直在做的那样使用CamelCasing
——据我所知,没有。