Researchers introduced a mutant gene into the fruit flies that is sensitive to temperature.
When the insects were warmed above 30 Celsius, communication between a particular set of nerve cells was disrupted.
This made the mutant males less interested in courting female flies and open to the advances of other males.
New knowledge
The flies reverted back to heterosexual courtship behaviours at cooler temperatures.
The study by Toshihiro Kitamoto, of the Beckman Research Institute of the City of Hope, California, US, is published in the journal Proceedings of the National Academy of Sciences.
Previous research has suggested that fruit fly (Drosophila melanogaster) sexual orientation is genetically determined, although the neuronal pathways important for controlling sexual preference are unclear.
Dr Kitamoto sought to explore these issues through the introduction of the mutant gene called shibire into the midst of the fruit fly's neurons.
Inactivated system
The normal gene plays an important role in the secretions of a chemical signal.
The results showed that relations between males are suppressed by the action of neurons whose role could be to detect or to interpret the signals of anti-aphrodisiac hormones, Dr Kitamoto said.
The neurons affected by the mutant gene include nerves sensitive to taste, located in the head and legs. The role of these neurons could be to halt the attraction between male fruit flies by detecting or interpreting aphrodisiac pheromones produced by other males.
Dr Kitamoto told the BBC: "My interpretation is that male-male courtship is somehow inhibited by certain systems in the fly nervous system and using my method I think I inactivated those inhibitory systems so male courtship is induced."