3 Replies Latest reply on Oct 11, 2007 5:26 PM by kglad

    Reference to 'stage.ground' Not Working- AS3

    monster356
      Alright, so i am having trouble with my class. it keeps kicking back this error:

      1119: Access of possibly undefined property ground through a reference with static type flash.display:DisplayObjectContainer.

      it's because "parent.ground" doesn't exist or something...

      this is the script:


      package {
      import flash.display.*;
      import flash.events.*;
      public class Base extends MovieClip {
      public static var cName:String;
      public var speed:Number = 3;
      private var grav:Number = 3, grounded:Boolean = false;
      public function Base():void {
      trace("Main Game Base Has Started...");
      stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKey);
      this.addEventListener(Event.ENTER_FRAME, main);
      }
      public function checkKey(event:KeyboardEvent):void {
      if (event.keyCode == 39) {
      this.x+=speed;
      }
      if (event.keyCode == 37) {
      this.x-=speed;
      }
      }
      public function main(event:Event):void {
      this.y += grav;
      if (grounded) {
      grav = 0;
      } else {
      grav++;
      }
      while (this.hitTestObject(parent.ground)){
      grounded = false;
      }
      }
      }
      }