Hello I have hard coded a game using the timeline. I want to transition to using document and separate classes. i have made a player class and added private functions that is keyUpFunction and keyDown to move the player. And added movePlayer function in document class.
I have exported a movieclip for actionscript linked to player class that has seperate frames for animation:
in my function on keypress Keyboard.RIGHT I want it to goToAndStop("walkRight")
I do not know how to reference it when it is not added to stage (no instance is chosen) if ya understand?
i tried this.gotoandstop('walkRight') but it does not work? so if i was to add 2 childs of the player on stage I cannot use dot notation to reference both to work?
if i was to use player1.gotoAndStop('walkRight') it would work?
If I understand correctly, you have your player functionality inside a "player" class? So your trouble is referencing your player class when it is not added to the stage?
Code:
var player:Player = new Player();
player.gotoAndStop("stand");
To access the timeline from inside the player class, this.gotoAndStop() should work, can you paste your code?
I get confused with where I add the instance is it in document class? because if it is then how is this referenced in the keyup and keydown functions that are in player class if i wanted to put movePlayer function into player class?
This is not syntactically correct just used to understand problem
document class
Code:
var player:Player = new Player();
player.gotoAndStop("stand");
function movePlayer () {
if (walkingLeft)
{player.x -= playerSpeed;}
if (walkingRight) += playerSpeed;
etc...
}
Yes, you add the instance of your class inside the document class. I believe the best way to do this is to not have any "moving" logic inside your player class. Add the Event Listeners inside the document class, and then simply move the player with it's MovieClip attributes (Because your player class derives from MovieClip).