I just had a quick question that some of you might know the answer to.
What is the best method of adding eventlisteners? I always see people clump them like this, so that there are multiple listeners at all times like this:
btn.addEventListener(MouseEvent.MOUSE_OVER, overFunction);
btn.addEventListener(MouseEvent.MOUSE_OUT, outFunction);
btn.addEventListener(MouseEvent.MOUSE_DOWN, downFunction);
function overFunction(e:MouseEvent):void{
}
function outFunction(e:MouseEvent):void{
}
Ive been doing them rather like this, which makes more sense to me. Only thing is that Ive never seen anyone elses code do this and Im assuming there is a reason that Im not aware about.
btn.addEventListener(MouseEvent.MOUSE_OVER, overFunction);
function overFunction(e:MouseEvent):void{
btn.removeEventListener(MouseEvent.MOUSE_OVER, overFunction);
btn.addEventListener(MouseEvent.MOUSE_OUT, outFunction);
btn.addEventListener(MouseEvent.MOUSE_DOWN, downFunction);
}
function outFunction(e:MouseEvent):void{
btn.removeEventListener(MouseEvent.MOUSE_OUT, outFunction);
btn.removeEventListener(MouseEvent.MOUSE_DOWN, downFunction);
btn.addEventListener(MouseEvent.MOUSE_OVER, overFunction);
}
Thanks