Tuesday, January 3rd, 2012
Regardless of what you think of Flash (you know who you are) ActionScript 3 is by far the most powerful front end language and it teaches the developer something important: class based development. Let’s be honest here, JavaScript is a huge hack of a language and considering it was one of the first languages I ever wrote, I will always prefer ActionScript 3 (but not necessarily Flash) over JavaScript.
Anyway, if you’re still writing ActionScript 3 then you most certainly have a base class and this base class should always (in my opinion) start like this:
{
import flash.display.Sprite;
import flash.events.Event;
[SWF( backgroundColor=0xffffff, frameRate=30, height=600, width=800 )]
public class App extends Sprite
{
public function App()
{
loaderInfo.addEventListener( Event.INIT, handleInit, false, 0, true );
}
private function handleInit(e:Event):void
{
loaderInfo.removeEventListener( Event.INIT, handleInit );
}
}
}
I’ve come across a lot of code in my time and a lot of problems stem from badly initialisation of the application before it’s embedded or even ready to have stuff drawn. By listening to the ‘loaderInfo‘ INIT event, you know your app’s ready. That is all.
