I see this kind of thing periodically:
addEventListener(Event.ENTER_FRAME, enterFrameListener);
function enterFrameListener(e:Event):void {
var aaa:Number = 10;
var bbb:Sprite = new Sprite();
// do stuff with aaa and bbb
}
This is just a quick example to illustrate my point. The thing I’m focusing on is declaration of the variables over and over again each time the listener fires. It strikes me that one would instead create aaa and bbb OUTSIDE of the listener and then go ahead and do stuff within the listener.
So my questions are:
[LIST=1]
[]Is the code as shown a best practice?
[]If it is, what’s happening, say, to the previously declared aaa each time a new one is declared?
[*]What is the performance difference between the code as shown and the alternative I discussed?
[/LIST]
Thanks!