Fireflies mainly emit light to attract mates, though this communication method is also used to defend territory. Though it is mostly adult fireflies that glow, there are some species where the larvae and the eggs also emit light.
Firefly, Detroit, Michigan The only thing I miss about living in the South - the beautiful sight of fireflies (They were wiped out in Urban areas in the by the mosquito abatement DDT applications - we had to drive out of town to see them)
Lightning bugs or fireflies are not flies, but they are beetles that can produce lights. Lightning bugs can light up during all stages of their lives, including larvae and pupae. In some species of lightning bugs, the eggs glow as well!