I was reading a tutorial on how you can make a turret follow the mouse, for a game, and I stumbled across something I’ve never seen before.
private function showGhostTurret(e:MouseEvent = null):void
{
var target_placeholder:Sprite = e.currentTarget as Sprite;
ghost_turret.x = target_placeholder.x;
ghost_turret.y = target_placeholder.y;
ghost_turret.visible = true;
}
I’ve never seen someone set the (e:Event) to null, like in the first line. Could someone please explain the purpose of doing this? Let me know if you need more information to answer.
Thanks.
That is a default parameter value. What it means is that the parameter
eis optional so you can opt to not include it in a call toshowGhostTurret()andewill be assigned the valuenull.I’m not sure how that’s useful in this particular case since, looking at the body of the function,
eis most definitely required. You said this was part of a tutorial — maybe it becomes useful later on?