Which is more efficient (performance wise):
A bunch of event listeners attached to buttons,
or a single event listener attached to the parent object, containing a switch statement?
Is the difference negligible, or is one more efficient, and why?
Example:
orCode:button1.addEventListener(MouseEvent.CLICK, function1); button2.addEventListener(MouseEvent.CLICK, function2); button3.addEventListener(MouseEvent.CLICK, function3); ..button356.addEventListener(MouseEvent.CLICK, function356); ...corresponding functions
Code:this.addEventListener(MouseEvent.CLICK, buttonClick); function buttonClick(event:MouseEvent):void { switch (event.target) { case button1: sugar += 10; break; case button2: salt += 10; break; ...etc } } }


Reply With Quote
