Actionscript:
-
package {
-
import adobe.utils.*;
-
import flash.accessibility.*;
-
import flash.display.*;
-
import flash.errors.*;
-
import flash.events.*;
-
import flash.external.*;
-
import flash.filters.*;
-
import flash.geom.*;
-
import flash.media.*;
-
import flash.net.*;
-
import flash.printing.*;
-
import flash.profiler.*;
-
import flash.sampler.*;
-
import flash.system.*;
-
import flash.text.*;
-
import flash.ui.*;
-
import flash.utils.*;
-
import flash.xml.*;
-
-
dynamic public class Snippet extends MovieClip {
-
public function Snippet() {
-
// paste your snippet here (functions and all)
-
}
-
}
-
}
This snippet imports all flash packages and is dynamic... you can copy actionsnippet code into the constructor of this file if you use Flex, FlashDevelop, TextMate etc... I tested it with a bunch of snippets and it seems to work nicely.
When I first teach classes in AS3 this is the template I use:
Actionscript:
-
package{
-
import flash.display.*;
-
import flash.events.*;
-
-
public class Main extends Sprite{
-
// etc...
-
}
-
}
Display and events cover a lot of ground..... next one I find myself adding is flash.geom, followed by flash.net... I'd say those are my top 4 most frequently used packages.... I do lots of text layout in the Flash IDE, otherwise flash.text would be in there....
4 Comments
This is silly - FlexBuilder or FlashDevelop will add the imports automatically for as you need them.
Cheers.
Thanks for the comment Philippe, but I’m pretty sure your wrong… at least about Flex. Flex is smart enough to add some import statements, but it’s not perfect…. and it only does this as you write them… simply try to copy and paste any of the larger sized posts on this site into a new actionscript flex project and you’ll see that flex won’t add any import statements…
Flex also wouldn’t and shouldn’t add the dynamic keyword automatically… I only used FlashDevelop when I used to have a PC…. so it’s possible that it is smart enough to read through code copy and pasted into the constructor….
If there is a way to get Flex to automatically add all required import statements to a chunk of copy and pasted code I’d love to know about it….
Sorry, please disregard my comment - to try random snippets you still have to go through some manual operations.
No worries Philippe…