Sunday, March 4, 2007

Coding problem in ActionScript

The following code generates a VerifyError when getInstance is called. VerifyError: Error #1030: Stack depth is unbalanced. 0 != 1. at SingletonTest$iinit() public class SingletonTest { private static var s_singleton:SingletonTest = null; public static function getInstance():SingletonTest { if (s_singleton == null) s_singleton = new SingletonTest(); //Fails at this line. return s_singleton; } public function SingletonTest() { super; try { } catch (e:Error) { } } } Can you guess why? The reason is the super call in the constructor which is missing the () ! Why wouldn't the compiler throw a error or ignore the statement?

No comments: