For starters, fireflies are not flies. "Flies" have one pair of wings (like houseflies) while all other winged insects have two pairs of wings, or, four wings altogether. Usually when the common name of an insect contains the word "fly" as part of a one word common name such as firefly, dragonfly or scorpionfly, the insects are not true flies and belong to another order of insects. ("Housefly," a true fly, is an exception to this rule.)

Fireflies are beetles, of the family Lampyridae.

Most known firefly species are bioluminescent as adults. However, all known firefly larvae are bioluminescent, as are firefly eggs. Also not all bioluminescent beetles are of the family Lampyridae, the true fireflies. Related beetle families that have bioluminescent members include some click beetles (family Elateridae), phengodid beetles (family Phengodidae) and several other very small families.

So, what is the purpose of lighting up like this? A few things we know, many ideas are the subject of speculation. It is thought that the larvae of fireflies have a bad taste to most predators, and that the light is intended to signal that fact. (It is known that mice, for example, will avoid such larvae.) In the adult, males seem attracted to females by exchange of a species-specific code of light signals. Perhaps this outweighs the obvious disadvantage of being so visible to predators; perhaps the adults, too, are bad-tasting.

Fireflies produce light via a chemical reaction consisting of Luciferin (a substrate) combined with Luciferase (an enzyme), ATP (adenosine triphosphate) and oxygen. When these components are added, light is produced. In essence the ATP, a potent energy source, is oxidized in the process.

There are several theories on how fireflies control the "on" and "off" of their photic organs; no one knows for sure. Perhaps the beetle controls the oxygen supply to the photic organ for use in the chemical reaction; perhaps some other messenger molecule is involved. In any case, very little heat is released: the animal remains cool though glowing.

Fireflies, both as adults and as larvae, like warmth and water, and are often found near the edges of streams or ponds. Some Asian species are fully aquatic (due to the presence of tracheal gills) and live underwater, feeding on aquatic snails. The greatest number of species are found in tropical Asia and Central and South America.

They occur, of course, in the eastern United States, where children catch them in jars on warm summer nights. If you live west of Kansas, however, you will never or almost never see one, though there are plenty of suitable habitats in the west. No one knows why they are not found there.

Some kinds of magic are found only in particular locations.

Phylum Arthorpoda, Subphylum Uniramia, Superclass Insecta, Class Pterygota, Subclass Endopterygota, Order Coleoptera, Family Lampyridae

See Crockett, Lawrence J., "Bioluminescence." Academic American Encyclopedia. 1997. Grolier Multimedia Encyclopedia. America Online. January 2, 1997.
Pearse, Buchsbaum, Living Invertibrates, Blackwell Scientific Publications, Boston, Massachusetts 1987;
http://iris.biosci.ohio-state.edu/projects/FFiles/frfact.html