6 Replies Latest reply on Nov 11, 2017 1:31 PM by eliw12510111

    Referencing own position inside class

    eliw12510111

      Hi,

       

      This might be kind of hard to explain since I'm so new.

       

      Essentially I'm creating a game where I want the player avatar to have its own class.

       

      I've added event listeners in the main class file that change the string values of variables DirectionY or DirectionX to "Up" "Down" or "Left" "Right", respectively, with the WASD keys.

      I'm them using an update function inside of the player class to basically say if DirectionX status is "Right" go right.

       

      The problem is, I have no idea how to reference the position of the movieclip connected to the player class in order to make it move.

       

      The Player is brought on to the stage like so

      var player:Player = new Player(); (The library object/visual representation of the player is also called Player, and I've put it's class as Player)

      Obviously, I can't just reference the instance name as if it were always on stage.

       

      I really don't want to have all the player avatar code in the main game class.