Archive of February 2010

February 11, 10

Including imports

Do you remember the #include "" AS2 directive? It was often used to include predefined prototype functions in AS2. Since using prototypes become obsolete in AS3 (in favour of the inheritance) the include in often underused. For example, Darron Shall suggests using include directive to mimic [multiple inheritance]( Recently, I had been given a glimpse of brain damage enlightenment and I started using it again in AS3 for including all project specific libs only. If you want to pass me the hammer now, please read on. ###How? Using wildcards (like import flash.display.*) is often considered a bad practice (or laziness) as we don't know what classes/packages are actually being imported. So we are left with typing all import directives for every class we write. Very commonly we use the same shared functionality (either a framework or built-in classes) in the SWF. The idea is that instead of having to import the same classes in every project class, we can have a list of them in a file, i.e.: import flash.display.Bitmap; import flash.display.MovieClip; import flash.display.Sprite; import; import; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.utils.setTimeout; import gs.TweenLite; and then stop worrying anymore about what needs to be imported. All you need to do is to place include "../../"; where your import directives would normally live. I've personally chosen to put it in the same location as the *source directory*. package net.blog2t { include "../../"; public class Banner extends Sprite { } } Then you can do it for every project specific class you add. If you're on OS X and using Textmate, you can use [the shortcut]( – F5 key to sort lines and remove duplicated entries.
06:00 PM | | 2 Comments | Tags: , , ,