How does the switch on my bike light work?

Stanleymonkey asked: I have an LED headlight on my bike. If I press the switch once it lights up.
If I press it again, it starts flashing – when I press it again it goes off.

How does that switch work? Does it use transistors in a speciall circuit – or is it something else?