Different elements emit different flame colors when heated by the same non-luminous flame because of the color of their radical.Some cations and anions have a different color to themselves.
For example-
Na+--> Burns with a golden flame;
Cu+--> Burns with a bluish green flame;
Ca+--> Burns with a brick red flame;
Hope i helped u:)
1 2 1
When element heated chemical bonds break and new ones form and make new molecules and releasing energy.The light is emitted when an excited electron drops from a higher energy state to a lower energy state.Every element has its own specific energy configuration for the electrons in the atom. so every element has its own specific light spectrum that it emits when electrons change orbitals.
and also, Wavelength (color) is directly related to energy (E=h/wavelength). 
Arsenic(As) - blue
sodium(Na) - bright yellow
zinc(Zn) - blue-green to pale green
lead(Pb) - blue
potassium(K) - light purple to red