好的,我正在编写一个函数,允许许多不同类型的项目符号与许多不同类型的对象进行交互:
private function checkBulletCollisions() :void{
var bullet:MovieClip;
for (var j:int = 0; j < shootableArray.length; j++){
shootableObject = shootableArray[j];
for(var i:int = 0; i < bulletArray.length; i++){
bullet = bulletArray[i];
if (shootableObject.hitTestPoint(bullet.x, bullet.y, true)) {
container.removeChild(bullet);
bulletArray.splice(i,1);
if (shootableArray[j] is Enemy){
shootableObject.enemyHealth += zArrow.power; //Working code for zArrow only
shootableObject.enemyHealth += bullet.power; //Error throwing code
//(I'm not using both lines at the same time, in case you were wondering)
if(shootableObject.enemyHealth <= 0){
container.removeChild(shootableArray[j]);
shootableArray.splice(j,1);
}
}
}
}
}
现在,我有两种类型的项目符号(zArrow和Dice)都扩展了Bullet类。这是zArrow类:
package
{
import Bullet;
public class zArrow extends Bullet
{
public static var power = -1
public function zArrow(anything:*):void
{
super(anything);
}
}
}
我试图根据两个子弹类中的任何一个中的“power”变量(无论哪个击中)来降低敌人对象的健康状况,但是我无法弄清楚为什么它一直在抛出以下错误:当我使用上面提到的问题代码时,我:
ReferenceError: Error #1069: Property power not found on zArrow and there is no default value.
at GameDocumentClass2/checkBulletCollisions()
at GameDocumentClass2/enterFrameHandler()
我肯定知道我正在尝试访问单个类的变量,为什么不读取变量呢?
答案 0 :(得分:1)
我看到你想通过类实例访问静态变量。静态变量是类变量。例如:如果您的类具有静态属性power
,则可以通过SomeButtonClass.power
方式访问它。
子类不会继承静态变量。只会继承非静态public
,protected
和internal
属性。