我想覆蓋父類的方法。我成功地完成了。但是當我嘗試訪問一個屬性。我得到以下錯誤1178:嘗試訪問通過靜態類型的引用留下的不可訪問的屬性
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;
}
}
}
這是壓倒一切的類
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
}
}
非常感謝。錯誤消息是說在該方法中的另一個變量是原因。我沒有注意到其他的變數 – numerical25 2010-01-06 23:55:04