Flash 1178:试图通过静态类型的引用访问不可访问的属性

Flash 1178:试图通过静态类型的引用访问不可访问的属性,flash,actionscript-3,actionscript,flash-cs4,Flash,Actionscript 3,Actionscript,Flash Cs4,我正在尝试重写父类方法。我成功地做到了这一点。但是当我尝试访问一个属性时。我得到以下错误 1178: Attempted access of inaccessible property left through a reference with static type 此属性是公共的,并且已定义。下面是我的代码 package com.objects { import flash.display.MovieClip; import flash.events.*; import flash.d

我正在尝试重写父类方法。我成功地做到了这一点。但是当我尝试访问一个属性时。我得到以下错误

1178: Attempted access of inaccessible property left through a reference with static type
此属性是公共的,并且已定义。下面是我的代码

package com.objects {

import flash.display.MovieClip;
import flash.events.*;
import flash.display.Stage;
import flash.geom.Rectangle;


public class Brick extends MovieClip {

public var points:Number = 100;
public var bWidth:Number = 50;
public var bHeight:Number = 20;
private var left:Number;
private var right:Number;
private var top:Number;
private var bottom:Number;
public var ball:Ball;
private var lastDistance:Number;
private var engine:Engine;

public var hit:Boolean;


public function Brick():void
{
stop();
addEventListener(Event.ENTER_FRAME, loop);
}

protected function loop(e:Event):void
{
updateArea();
checkBall();
}
protected function updateArea():void {
left = x;
right = x + bWidth;
top = y;
bottom = y + bHeight;
}

protected function killSelf():void {
engine.score += points;
engine.numberOfBricks -= 1;
removeEventListener(Event.ENTER_FRAME,loop);
engine.removeChild(this);
}

protected function checkBall():void
{
if(hitTestObject(ball))
{

if((ball.x + 5) < left)
{
ball.xspeed *= -1;
ball.x -= ball.xspeed + 10;
killSelf();
}
else if((ball.x - 5) > right)
{
ball.xspeed *= -1;
ball.x += ball.xspeed+10;
killSelf();
}

else if(ball.y > bottom && ball.x > left && ball.x < right)
{
ball.yspeed *= -1;
ball.y += ball.yspeed+10;
killSelf();

}
else if(ball.y < top && ball.x > left && ball.x < right)
{
ball.yspeed *= -1;
ball.y -= ball.yspeed+10;
killSelf();                 
}

}
}//End CheckBall

public function getEngine(engine:Engine):void
{
this.engine = engine;
}
public function getBall(ball:Ball):void
{
this.ball = ball;
}
}
} 
包com.objects{
导入flash.display.MovieClip;
导入flash.events.*;
导入flash.display.Stage;
导入flash.geom.Rectangle;
公共类Brick扩展了MovieClip{
公共var点:数量=100;
公共变量b宽度:数字=50;
公共变量BHHEIGHT:数字=20;
私有变量左:数字;
私权:数字;
私人var top:数字;
私有变量底部:数字;
公共足球:足球;
私人距离:数字;
私有var引擎:引擎;
公共变量hit:Boolean;
公共函数Brick():void
{
停止();
addEventListener(Event.ENTER_FRAME,循环);
}
受保护的函数循环(e:事件):无效
{
updateArea();
方格球();
}
受保护的函数updateArea():void{
左=x;
右=x+B宽度;
top=y;
底部=y+B八度;
}
受保护的函数killSelf():void{
engine.score+=分数;
engine.numberOfBricks-=1;
removeEventListener(事件。输入\帧,循环);
发动机。移除Child(此);
}
受保护函数checkBall():void
{
if(hitTestObject(ball))
{
如果((球x+5)<左)
{
ball.x速度*=-1;
ball.x-=ball.x速度+10;
killSelf();
}
如果((ball.x-5)>右侧),则为else
{
ball.x速度*=-1;
ball.x+=ball.x速度+10;
killSelf();
}
else if(ball.y>底部和&ball.x>左侧和&ball.x<右侧)
{
ball.y速度*=-1;
ball.y+=ball.y速度+10;
killSelf();
}
else if(ball.yleft&&ball.x
下面是重写类

package com.objects {

    import flash.display.MovieClip;
    import flash.events.*;
    import flash.display.Stage;
    import flash.geom.Rectangle;


    public class Brick2 extends Brick {

        private var armor:Number = 2;

        public function Brick2():void
        {
            gotoAndStop(2);
        }

        override protected function checkBall():void
        {
            if(hitTestObject(this.ball))
            {
                if(armor <=0){

                    if((this.ball.x + 5) < left)
                    {
                        this.ball.xspeed *= -1;
                        this.ball.x -= this.ball.xspeed + 10;
                        killSelf();
                    }
                    else if((this.ball.x - 5) > right)
                    {
                        this.ball.xspeed *= -1;
                        this.ball.x += this.ball.xspeed+10;
                        killSelf();
                    }

                    else if(this.ball.y > bottom && this.ball.x > left && this.ball.x < right)
                    {
                        this.ball.yspeed *= -1;
                        this.ball.y += this.ball.yspeed+10;
                        killSelf();

                    }
                    else if(this.ball.y < top && this.ball.x > left && this.ball.x < right)
                    {
                        this.ball.yspeed *= -1;
                        this.ball.y -= this.ball.yspeed+10;
                        killSelf();                 
                    }
                }//end armor condition
                else
                {
                    --armor
                }
            }
        }//End Checkthis.ball

    }
}
包com.objects{
导入flash.display.MovieClip;
导入flash.events.*;
导入flash.display.Stage;
导入flash.geom.Rectangle;
公共级砖2扩展砖{
私人var装甲:数量=2;
公共函数Brick2():void
{
gotoAndStop(2);
}
重写受保护的函数checkBall():void
{
if(hitTestObject(this.ball))
{
如果(右)
{
this.ball.xspeed*=-1;
this.ball.x+=this.ball.xspeed+10;
killSelf();
}
else if(this.ball.y>底部和this.ball.x>左侧和this.ball.x<右侧)
{
this.ball.yspeed*=-1;
this.ball.y+=this.ball.yspeed+10;
killSelf();
}
else if(this.ball.yleft&&this.ball.x
如果要在子类中使用变量,必须对其进行保护,而不是私有


Private表示只有该类可以看到它,protected表示该类及其子类。

在基类中,
var left
被声明为Private。尝试从其他地方(包括子类)访问它将失败。

对于这种情况,我为自己找到了一个简单的解决方法。 读取属性时,请使用普通actionscript getter。 但是,与优雅的actionscript setter不同,只需指定类似java的setter

public function get property():Number { return _property; }
myCustomNamespace function setProperty(value:Number):void { _property = value; }

非常感谢。错误消息说,该方法中的另一个变量是原因。我没有注意到其他没有注意到的变量