to super or not to super
Sometimes thereĀ are reasons for not calling the base class constructor. A little trick in AS3.0 to not super() your base class is the following line of code:
if (0) super();
Written by Sander Wichers at December 17, 2007
Filed Under Actionscript |
Filed Under Actionscript |
I actually do not understand why we should do this.
Simply not having super(); should also work isn’t it?
super(); will always get called! The only flexibility you have is the position where you want to execute it within your constructor!
The if (0) trick makes Flash believe it will actually execute a super() call so it will not add super() dynamically to your script (it does this in preparsing state).
Thanks YOU!
This was exactly what I was looking for. I tried something like this “if(false){super;}” but I guess the pre-compiler was able to see through it. As far as one use-case when this is code is needed… overriding singleton classes such as the Cairngorm servicelocator.