PDA

View Full Version : creating methods with the same name but diff arguements?



zoink
October 6th, 2008, 01:06 PM
is there a way to create methods with the same name but with different arguements?

I have a method that listens to Mouse_DOWN event. So it's something like

function myFunction(evt:MouseEvent):void
{
//myFunction
}

For example i want to use myFunction even without the Mouse_DOWN event... how do i do that?

senocular
October 6th, 2008, 01:15 PM
This is called method "overloading". ActionScript does not support it, but for what you're asking, you can just give evt a default value of null (myFunction(evt:MouseEvent = null):void), then you can call it without having to include evt at all.

For other more complicated situations, you'd have to use the ...rest parameter and dissect the arguments received at runtime to determine which variation of the method you need to use.

mpelland
October 6th, 2008, 01:17 PM
name it differently? set a default value to the MouseEvent? I don't believe that you can have multiple functions/methods with the same name.

zoink
October 6th, 2008, 01:20 PM
I see. Flash doesn't support method overloading.. Thanks for the help guys. =)