Andre Angelo
Andre Angelo

Reputation: 281

AS3 - e:MouseEvent = null?

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.

Upvotes: 0

Views: 976

Answers (1)

NoobsArePeople2
NoobsArePeople2

Reputation: 1996

That is a default parameter value. What it means is that the parameter e is optional so you can opt to not include it in a call to showGhostTurret() and e will be assigned the value null.

I'm not sure how that's useful in this particular case since, looking at the body of the function, e is most definitely required. You said this was part of a tutorial -- maybe it becomes useful later on?

Upvotes: 3

Related Questions