Crazy Question
Ok I'm not sure if it's actually crazy or not but I seem to be having a REALLY hard time finding anyone else who has a similar question to mine.
I'll explain what I'm trying to do so you can all understand my question.
So:
I have 10 buttons on the stage at once. (We'll call them TestButtons for reference sake)
I want each button to do something different to the player's avatar based on whichever button is clicked. (IE: button 1 moves player to the left, button 2 moves player right, button 3 spins player around... just as an example)
I could easily do this by creating 10 different event listeners, and then 10 unique event handlers, but that would be tedious.
I'm trying to make my code as small and organized as possible, so what I want to do instead is include the event listener and the event handler inside the TestButton class file.
This worked no problem. Using only code, I created 10 unique instances of my TestButton on the screen, each with its own built-in listener and handler.
But now I want to change the x value of the player's avatar on the screen using these buttons...
Back in my main file, I have the code:
var playerOne:Player = new Player();
addChild(playerOne);
and since Player is defined elsewhere as an extension of MovieClip, playerOne inherently possesses an x value.
HOWEVER, when I include this code in the TestButton class event handler:
public function clickHandler(event:MouseEvent):void {
playerOne.x = 3;
}
It just tells me "access of undefined property playerOne"....
playerOne is definitely defined. It's defined inside the game's main.as file. But my TestButton.as file can't seem to see it...
I figured this could be solved by passing an argument from my one of my testButton's into the main file... but I also can't do that.
It seems that my testButtons cannot communicate in any way with any other variables outside of their own.
Which makes no sense to me... why is it that in my main file I can reference testButton.x, but in my TestButton file I can't access playerOne.x?