You can't beat it with a stick

Flash AS3: Stop using “Automatically Declare Stage Instances”

If you are compiling in the Flash IDE, you need to turn OFF the “Automatically Declare Stage Instances” option. It’s simple to do… go to File>Publish Settings, then click on the “Flash” tab and click the “Settings” button next to the Actionscript 3.0 dropdown. Simply uncheck the box and you’re done. It’s a crutch that is turned on by default in Flash and using it is a bad idea. Here are 4 quick reasons not to use it:

  1. No more mystery variables in your classes. If you ever have to hand off your work to someone else, it’s really helpful to have all stage instances declared in your classes:
    public var foo_mc:MovieClip //foo_mc is a stage instance
    

    It’s just a courtesy to other developers who might have to deal with your code.

  2. It fixes SOME inheritance problems. Flash is a little funny about class inheritance and it sometimes chokes on things that seem like they should be valid subclassing to me. But, I have found that I have a lot less trouble with it since I started explicitly declaring all stage instances.
  3. Your code will integrate better with a Flex environment. I don’t use Flex (now FlashBuilder) much, but I do sometimes build fancy schmancy animated components for use with Flex. You have to declare all stage instances in your class variable declarations for this to work. You might never have to deal with this, but why not create a workflow that is more portable?
  4. ASDocs requires it. If you want to create documentation for your classes using ASDocs, you must have all of your stage instances declared. Otherwise, it throws an error on each one that you didn’t declare.

I’m sure there are even more reasons than this, but those are the ones that I’ve found. Leaving “Automatically Declare Stage Instances” turned on is lazy, so knock it off.

Previous

Flash AS3: Track SWF memory usage and framerate with SWFProfiler

Next

Flash CS5: TLF textfield bugs (or TLF WTF?)

3 Comments

  1. It’s been so long since i used flash – and when i do – it’s in conjunction with FDT/ FB4.

    Unchecking ‘Automatically Declare Stage Instances’ – makes the code more readable, manageable, and stops FDT / FB4 showing errors for variables that get injected into your class… anyway… yep – i agree with you there. Maybe not the best solution for designers, but well – i prefer using SWC’s – and coding elsewhere anyway….

  2. dude!!! thx for the simple answer, i manage to get it and now i’ll can do a lot of things, may i subscribe to your web 🙂 thx u~

  3. I started unchecking this setting so that I could get MovieClip introspection in FlashDevelop. Then all the other good reasons became obvious that are listed above. Now it is one of the first things I do when fixing other people’s code.

Powered by WordPress & Theme by Anders Norén