Cannot access constant through itemRenderer using parentDocument
I have an itemRenderer inside a dataGrid, and I am able to access variables on the mxml file (in a *.as script file referenced from the mxml) using parentDocum开发者_开发百科ent
. However, I am unable to access a constant in the same script file. If I change the constant to a regular var, I can access it.
I created a getter function for the constant and it works, but why can't the constant be accessed directly?
Thanks
Constants are generally static, and therefore access via the class. Getters / Setters are members, and therefore accessed via an instance.
Therefore, to get access to a constant, you need to have an explicit reference to the class.
Something like parentDocument.MY_CONSTANT
wouldn't work, however MyClass(parentDocument).MY_CONSTANT
would.
精彩评论