In AS3, why do we put our import statements in the package statement, and not inside the Class declaration?
This is a typical (but rather pointless) AS3 class:
package my.foo.package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class FooClass extends MovieClip
{
public static const EVENT_TIME_UP:String = 'timeUpEvent';
public function FooClass()
{
var timer:Timer = new Timer(2000, 1);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
private function timerHandler(e:TimerEvent):void
{
dispatchEvent(new Event(FooClass.EVENT_TIME_UP));
}
}
}
But why are all the import statements meant to go all the way up there, outside on the Class? The class works perfectly fine when I move the imports to inside the class declaration like below.
package my.foo.package
{
import flash.display.MovieClip;
public class FooClass extends MovieClip
{
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
public static const EVENT_TIME_UP:String = 'timeUpEvent';
public function FooClass()
{
var timer:Timer = new Timer(2000, 1);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
private function timerHandler(e:TimerEvent):void
{
dispatchEvent(new Event(FooClass.EVENT_TIME_UP));
}
}
}
It's only the MovieClip import that needs to be in package, because my class is extending it.
There is nothing helpful about this in the Adobe AS3 coding conventions.
So why do we put the imports in the package and not the class that's actually using them. The package is not using the imported classes is it? And why does it still work if I move the imports into the Class?