1:
target ( currentTarget) event:MouseEvent - , ( , ). , ( , event.target), , ,
if (event.target == button1) { doSomething();}
else if (event.target == button2) { doSomethingElse();}
, , .
2:
Haxe , , .
, , , , event.target , , , - - . - , , .
, , , , .
swordMenu.addEventListener(MouseEvent.CLICK, choose.bind(_,"sword"));
bowMenu.addEventListener(MouseEvent.CLICK, choose.bind(_,"bow"));
staffMenu.addEventListener(MouseEvent.CLICK, choose.bind(_,"staff"));
public function choose (event:MouseEvent,id:String):Void {
if(id == "sword") { onSword();}
if(id == "bow") { onBow();}
if(id == "staff") { onStaff();}
}
, - addEventListener. "bind()" . Haxe ".bind()", , , .
, :
swordMenu.addEventListener(MouseEvent.CLICK, choose.bind(_,"sword"));
_ " , ", "" .
:
swordMenu.addEventListener(MouseEvent.CLICK,
function(e:MouseEvent):Void
{
choose(e,"sword");
}
);
bowMenu.addEventListener(MouseEvent.CLICK,
function(e:MouseEvent):Void
{
choose(e,"bow");
}
);
staffMenu.addEventListener(MouseEvent.CLICK,
function(e:MouseEvent):Void
{
choose(e,"staff");
}
);
public function choose (event:MouseEvent,id:String):Void {
if(id == "sword") { onSword();}
if(id == "bow") { onBow();}
if(id == "staff") { onStaff();}
}
, .