Bad design in Flash CS3
Dealing with automatic declaration of stage instances in flash. 2008-05-12
Its unusual how you can work with a technology for a very long time, have no problems with it, and then suddenly come across a major mindbender. I've been using AS3 for years now, and never had an issue with this, probably because I stay away from the timeline.
I wanted to use inheritance to create a simple AlertBase for a project. It turns out that inheritance with symbols on the timeline is a big compiler explosion:
1152: A conflict exists with inherited definition AlertBase.okButton in namespace public.
Check out some source examples here.
It turns out that there is a little hidden checkbox that should, in my opinion, be off by default. In Publish Settings->Flash->ActionScript 3 Settings, there is a checkbox labeled 'Automatically declare stage instances.'.
This means that Flash will declare variables in your classes for all items on the stage. This would be great if it worked as expected, but from the example fla you can see that extending classes quickly breaks this functionality.
This is an unusual problem as it really forks AS3 code that extends symbols: code with the box checked, and code without. I've been using Papervision, and they are in the 'unchecked' camp, which is how I found out there is a difference.
I would recommend that this checkbox is unchecked on every fla you work on. You shouldn't allow flash to write code for you if it cannot accurately reflect your intentions. You should also do your best to inform your team that this is the best practice. From an industry perspective, I'm unable to determine if this is a best practice. I believe strongly that it should be, and hope that others will agree and pass on this opinion.
|