Calling Button Functions from Elsewhere AS3
- January 25th, 2011
- Write comment
Usually when you set up a button listener in actionscript 3 it listens for a mouse event and then fires a function. That functions needs to have the mouse event set as a parameter like this book now buttom function:
bookNow.addEventListener(MouseEvent.MOUSE_DOWN,setupBooking);
function setupBooking(event:MouseEvent){
//this is where the functions methods are written
}
The problem is that if I want to call that function from some other place in my code, like from within another function, ie.
setupBooking();
the error fires saying “expecting 1 argument but it received 0.”
The way around this is to declare the argument as null in the function definition, like this:
function setupBooking(event:MouseEvent=null){
}
then we can call it with or without an argument.
