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()?
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()?
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.
public class Game{
private var age = 10;
public static function getAge() {
return self.age;
}
}
public class Display{
public function whatever() {
trace( Game.getAge() );
}
}