Why are stellar absorption line spectra passed through a cold gas? I am currently studying spectral lines and saw in my notes that the way in which the absorbtion line spectra for a star was measured was by taking its light and shining it through a cold gas. The remaining light would show a black body spectrum with dark lines at the wavelengths which correspond to an exact difference in energy levels between two orbitals for an electron.
My question is, isn't this sort of spectroscopy supposed to identify the elemental composition of the star? It seems to me this would identify what elements were in the cold gas instead. 
Note: I am asking whether the measured absorption spectra represents the stars or the cold gas. If it measures the stars, why? Wouldn't changing the gas change the wavelengths at which electrons will make a transition?
 A: One has not to make confusion between the way we can create an absorption spectrum in laboratory (making radiation with a continuum spectrum passing through a cold gas) and the way absorption spectra are formed in the photosphere of a star or by absorption by planet atmospheres or interstellar gases. In the astrophysical case, spectroscopists have only to collect the light coming from far sources. 
No need to use a further absorbing layer which could not say anything about composition of far objects. Absorption lines in solar spectrum were observed for the first time by Fraunhofer  mid-19th century. Basic starting information about absorption spectroscopy can be found in this wikipedia page.
A: 
I am currently studying spectral lines and saw in my notes that the way in which the absorbtion line spectra for a star was measured was by taking its light and shining it through a cold gas.

The absorption spectrum of a star is generated when light coming from within the photosphere passes through the "cold" outer atmosphere of the star (where "cold" in this context merely means that the vast majority of the atoms are in the ground state, which can be quite hot indeed by human standards). To get the absorption spectrum of the star, we simply directly measure the light coming towards us.
A: The idea of shining light from a (hot) source through a cold gas is a very basic model of what a stellar atmosphere is like.
The radiation field emitted from hotter interior layers has to pass through cooler outer layers before it gets to us. This is how absorption lines become imprinted on what otherwise would be a featureless continuum. In other words, the star's radiation is self-absorbed by its outer, cooler layers.
A good way to look at this is that the photons we receive come from the layer at which the optical depth (at that wavelength) is approximately unity. i.e. We see down into the atmosphere as far as a mean free path for a photon of that wavelength.
Because the solar interior gets hotter as we go inwards and the radiation field approximates to a Planck blackbody function, then if the mean free path is long at a particular wavelength we see deeper, hotter and therefore brighter. On the other hand, if the mean free path is short (for example because there is a radiative transition of some type of atom at that wavelength and that element exists in the atmosphere), then our view will be to shallower depths and cooler temperatures, meaning less intense light. 
The mean free path will be proportional to the number density of that particular type of atom and thus by measuring the strength of absorption lines we get not just the indication of the presence of a particular species of atom, but also its number density (a.k.a. its abundance).
