Hi, I’m not a pro actionscripter but often asked to show some of my code to potential employers to prove that I’m not a total lunatic. I came to wonder whether my code is optimal or not and if it could be improved to be more efficient.
First, is there a book a website or something else that talks about optimizing your code (garbage collection, memory etc…)?
My second question goes with a concrete example of what I wonder about, here is an instance of the Loader class that I am creating in a custom class like this for an image gallery:
public class CustomClass extends Sprite {
public var loader:Loader;
public function CustomClass(url:String) {
init(url);
}
private function init(url:String):void {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, initListener);
var urlRequest:URLRequest = new URLRequest(url);
loader.load(urlRequest);
}
private function initListener(e:Event):void {
var loaderData:BitmapData = Bitmap(loader.content).bitmapData;
var b:Bitmap = new Bitmap(loaderData);
b.smoothing = true;
addChild(b);
trace("bitmap smoothing of " + loader.contentLoaderInfo+ " is " + b.smoothing);
}
}
After creating a new instance of this CustomClass, I directly access the loader as loader.load() to change the picture after some events are triggered. The event listener (initListener) is however triggered every time I use the loader.load() and adds a child bitmap again and again. So what I came to wonder is whether I’ve got a huge pile of images under each other without doing anything for them to be removed. Is there a way to replace the previous instance of b rather than add one every time or does it make no difference at all because Flash takes care of getting rid of it.
Thanks,