I am developing flash game.
first class:
public class Game{
public var age;
}
second class:
public class Display{
Game.age //<-- cannot retrieve
}
so how to get the variable from Game() to Display()?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See this other post about the difference between static variables and non-static variables:
Actionscript 3: Can someone explain to me the concept of static variables and methods?
You’re attempting to access age as a static variable, when it is, in fact, not one.
To access it in your code, you would have to instance the Game class and then reference “age” on the instance of the class.
After looking at this further, I feel I should point out that if you intend the “age” property of the Game class to be read-only, you should not make it public and instead create a static method on the Game class which can return the information to you.