Gotcha with ActionScript ‘const’

ActionScript (like JavaScript) lets you access object properties using two different notations. Consider the following class class A { public const CONSTANT:int = 34; } var a:A = new A(); The CONSTANT property of object a can be referred using the following two formats: a.CONSTANT a["CONSTANT"] Since CONSTANT is declared using const, it cannot be assigned a new value later on. So the following code doesn’t compile (as expected): a.CONSTANT = 23; However, the following code compiles and only throws an exception at run-time:...

April 13, 2009