Copy link to clipboard
Copied
hii plz help .. i make drag and drop game and i won't make one function(hitsa7an) to all the elements (juse,cheesy,batter,avocado)
how i make it ??
-----------------------------------------------------------------------------------
juse.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;
juse.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;
cheesy.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;
cheesy.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;
batter.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;
batter.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;
avocado.addEventListener(MouseEvent.MOUSE_DOWN,startdraging) ;
avocado.addEventListener(MouseEvent.MOUSE_UP,stopdraging) ;
function startdraging(e:MouseEvent):void{
e.currentTarget.startDrag();
}
function stopdraging (e:MouseEvent):void{
e.currentTarget.stopDrag();
}
addEventListener(Event.ENTER_FRAME,hitsa7an);
function hitsa7an (e:Event):void{
if(avocado.hitTestObject(sa7an)){
nonoM.gotoAndStop(2);
}else { nonoM.gotoAndStop(1); }
}
Copy link to clipboard
Copied
it's not clear what you're trying to do but typically when an object's dropped, you would check and then do something with the dropped object (instead of using an enterframe loop):
function stopdraging (e:MouseEvent):void{
e.currentTarget.stopDrag();
checkDroppedF(MovieClip(e.currentTarget)); // assuming you're using movieclips
}
function checkDroppedF(mc:MovieClip):void{
if(mc.hitTestObject(mc.target)){
// do whatever
} else {
// do whatever else
}
}