lundi 30 novembre 2015

AS3: How do I access a variable from a parent object?

I'm new to AS3 and my code may look a bit off.

Basically, how my program works is that I have an instance of "Level" on the stage, and it is a MovieClip containing several other objects which are also MovieClips with their own document class. In the "Level" class, I can access the X and Y position from the instance of "Player", but in my "Arrow" class, which is also a child of Level, I'm unable to access the X and Y of "Player". What I tried to do is set a public static variable called playerX and playerY in the Level class and assign that to the player's x and y position every frame, and I try accessing the variable in the Arrow class by doing "var x:Number = Object(parent).playerX, I've also tried MovieClip(parent).playerX and parent.playerX and just player X, neither of them work.

So to sum it up, I need to access a variable from a parent class, but every way I have tried it just returns an error.

Sorry if this was a bit unclear, any help will be much appreciated!

Aucun commentaire:

Enregistrer un commentaire