what happens to the loosely held electrons when each ion is heated in the flame

They are either moved to a higher energy level associated with the atom OR the electron can be moved so far away it ionizes the atom. Whether that happens or not depends upon the temperature of the flame.