I am trying to write a simple code that makes a movieclip bounce around the stage, yet every time I test the movie it gives me this error:
1195: Attempted access of inaccessible method stageWidth through reference of static type flash.display:Stage
I have two classes, one called mover which looks like this:
*package {
import flash.display.MovieClip;
import flash.events.Event;
public class Mover extends MovieClip{
public var targetMC:MovieClip;
public var xVel:Number;
public var yVel:Number;
function Mover(targetMC:MovieClip, xVel:Number, yVel:Number) {
this.targetMC = targetMC
this.xVel = xVel;
this.yVel = yVel;
}
function updatePosition(evtObj:Event):void {
this.targetMC.x += this.xVel;
this.targetMC.y += this.yVel;
}
public function startMoving():void {
this.targetMC.addEventListener(Event.ENTER_FRAME, this.updatePosition);
}
public function stopMoving():void {
this.targetMC.removeEventListener(Event.ENTER_FRAME, this.updatePosition);
}
}
}*
and another called Bouncer, which looks like this:
*package {
import flash.display.MovieClip
import Mover;
import flash.events.Event;
public class Bouncer extends Mover{
public function Bouncer(targetMC:MovieClip, xVel:Number, yVel:Number) {
super(targetMC,xVel,yVel);
}
private function bounceAtBorder():void {
if (this.targetMC.x > this.targetMC.stage.stageWidth(this.targetMC.width/2)) {
trace("Bounce at right edge");
this.targetMC.x = this.targetMC.stage.stageWidth(this.targetMC.width/2);
this.xVel *= -1;
}
if (this.targetMC.y > this.targetMC.stage.stageHeight(this.targetMC.height/2)){
trace("Bounce at bottom edge");
this.targetMC.y = this.targetMC.stage.stageHeight(this.targetMC.height/2);
this.yVel*=-1
}
if(this.targetMC.x < this.targetMC.width/2) {
trace("Bounce at left edge");
this.targetMC.x = this.targetMC.width/2;
this.xVel *= -1
}
if (this.targetMC.y < this.targetMC.height/2) {
trace ("Bounce at top edge");
this.targetMC.y = this.targetMC.height/2;
this.yVel *= - 1;
}
}
override function updatePosition(evtObj:Event):void {
super.updatePosition(evtObj);
this.bounceAtBorder();
}
}
}
*
What do I need to do to fix this?