PDA

View Full Version : How do I use the same function for different objects?


jjhoal
10-13-2007, 03:22 AM
for example I have 3 buttons to drag. btn1, bt2, btn3. This is the code I use,

function dragStart (event:MouseEvent):void
{
btn1.startDrag();
}
btn1.addEventListener(MouseEvent:MOUSE_DOWN, dragStart);

Now this code enbales btn1 to be dragged, what should i do to use the same function "dragStart" for btn2 and btn3? or do I have to declare another function for them? In the real project that im building I have lots of object to drag and if I have to name different functions for each item, that would be a big problem.

Or is there any way like having

if(btn1.isClicked ==true)
{
btn1.startDrag();
}

Im really new to AS 3.0. Hope someone out there can help..


:confused: :confused:

Flash Gordon
10-13-2007, 04:15 AM
function dragStart (event:MouseEvent):void
{
Sprite(event.currentTarget).startDrag();
}

jjhoal
10-15-2007, 01:44 AM
That was a big help! Thanks so much!:p Thanks Flash Gordon!