Reputation: 1541
I have something like this :
class ParentClass
{
public static const ON_SOME_EVT:String = "onSomeEvent" ;
....
}
class ChildClass extends ParentClass
{
....
}
main()
{
trace( ChildClass.ON_SOME_EVT ) ; //<< compiler error on doing this
//1119: Access of possibly undefined property ABC through a reference with static type Class.
}
Then how should i achieve this. I want to access the constant via child class but not the parent class.
Thanks.
Upvotes: 1
Views: 529
Reputation: 216
The best way to do this is just to re-declare your static const in the child class and reference the ParentClass.ON_SOME_EVT.
class ParentClass
{
public static const ON_SOME_EVT:String = "onSomeEvent" ;
....
}
class ChildClass extends ParentClass
{
public static const ON_SOME_EVT:STring = ParentClass.ON_SOME_EVT;
....
}
Upvotes: 1
Reputation: 4870
I think you can just do trace(ON_SOME_EVT);
in the ChildClass, because the constant is inherited too if I'm not mistaken.
But the constant is a static member of ParentClass
so outside of the inheritance tree you cannot avoid using ParentClass.ON_SOME_EVT
. Why don't you want to use that?
Upvotes: 1