views:

510

answers:

2

I am trying to override a parent class method. I successfully done so. But when I try to access a property. i get the following error

1178: Attempted access of inaccessible property left through a reference with static type

This property is public and it is defined. below is my code

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;
}
}
} 

Here is the overriding class

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

    }
}
+1  A: 

If you want to use a variable in a subclass, it has to be protected, not private.

Private means that only that class can see it, protected means that class and it's subclasses.

Ipsquiggle
+1  A: 

In your base class, var left is declared as private. Trying to access it from elsewhere, including descendant classes will fail.

spender
thanks alot. the error message was saying another varible in that method was the reason why. I wasnt paying attention to the other varibles that werent
numerical25