Is there any benefit to removing the event parameter from event handlers if it’s not used? I have the following instance:
<s:Button rollOver="handleRollOver(event)" rollOut="handleRollOut(event)"/>
And the following code:
private function handleRollOver(event:Event):void
{
// doing stuff
}
private function handleRollOut(event:Event):void
{
// doing stuff
}
Is there any benefit to removing the event object if it’s not used? For example, changing it to this:
<s:Button rollOver="handleRollOver()" rollOut="handleRollOut()"/>
And the following code:
private function handleRollOver():void
{
// doing stuff
}
private function handleRollOut():void
{
// doing stuff
}
The reason I ask is for a couple of reasons. One is that I heard that events bubble through all the display objects so if you can stop them that saves some CPU (not sure how much). But that would involve calling event.stopProp() type of calls correct not merely and at capture time rather than bubble time? Also, I heard that typing the event helps save CPU, so event:Event is slower than event:MouseEvent. I can try and find sources but until then maybe someone knows what I’m talking about. Thanks
I don’t believe there is any benefit, but there is no downside either. It works, nothing will error out. You just won’t have access to event properties. In the case of MXML, make sure you do not pass an event, otherwise you will get an error.
Regardless, it is best practice to always pass events, regardless if you need to or not. It may be more convenient, but it makes your code less flexible and less recognizable when searching through it.
If you are looking for a way to call the event handler without including an event, you can do this:
Setting a default value of null for the event argument allows you bypass that requirement with zero issues. At this point, every single event handler I set up has a default value of null, sometimes with added arguments too, just so that I can call it manually if I need to.