Those transitions emit light of very specific frequencies, characteristic of the chemical element itself. Therefore, the flame gets the color, which is primarily determined by properties of the atomic energy shells of the chemical element of the substance being put into flame.