use event function for multiple events
I've got several movieclip buttons on stage. For one of those buttons I've started of with:
button1.buttonMode = true;
button1.useHandCursor = true;
//
button1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
//;
function fl_ClickToDrag(event:MouseEvent):void
{
button1.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
{
button1.stopDrag();
}
Which works. But I would like to have that fl_ClickToDrag function excuted for all my other buttons too, so I don't have to duplicate that several times for each button. So I thought I use something like:
button1.buttonMode = true;
button1.useHandCursor = true;
button2.buttonMode = true;
button2.useHandCursor = true;
//
button1.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
button2.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
//;
function fl_ClickToDrag(event:MouseEvent):void
{
event.target.startDrag();
}
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
function fl_ReleaseToDrop(event:MouseEvent):void
{
event.target.stopDrag();
}
But that gives an error. What's the correct way?