I believe a good neurologist could answer your question in a flash.
(Am I a good neurologist? Well … noooo.)
However I DO know that a lot is understood about the sleep process, and a lot of bizarre anomalies do happen.
Who among us has been on the delicate verge of sleep, comfy and cozy, only to have the sudden sensation of falling - even though you’re sound in bed - ! and been violently woken up?
More rarely, who among us has been awake and aware, but totally unable to move (in that terrifying nightmare that is sleep paralysis,) possibly convinced you are dying?
In essence, many of these amonalies are a schism between your mind believing you are asleep, and your body not having been informed of this fact.
When we’re in REM sleep, our bodies want to enact our vivid dreams. Thankfully our bodies produce chemicals that keep us immobile.
Conversely, if you happen to consciously awaken while the rest of your being is paralyzed by the REM process, it can be quite terrifying.
I believe your situation is similar. While you fall asleep, your subconcsious dream apparatus is ready to go. If an outside (real) sound interferes, your subconscious might produce a
corresponding (imaginary) flash of light. However, I’ve heard of spontaneous neural discharges at the moment of falling asleep, similar to the sudden feeling of falling, expressed as a loud noise or flash of light at the moment of losing consciousness to sleep.
Hope this helps. Sorry I have no links or references. I believe that most of what I said is common knowledge, and hope that some dopers (maybe with Inet connections faster than my 12.0 Kbps!) can help you out. Your question fascinated me.