Question: To all the people with good ears:

when you're figuring out a melody by ear, are you listening to the sequence of notes and figuring out where each note sits relative to the root of the key?  

Or are you figuring out what the next note is by the interval from the last note?

Answer: 
Many good answers here already, but I'd like to keep it simple:

**Use all the clues that you can get, starting from the easiest**.

If the interval from the previous note is obvious, use that.

If the interval to the root is what stands out, use that.

If you're not sure and you have an instrument with you, use that -- figure out how to play the phrase on your instrument, and then write what you play.
I don't rate my ear as good, but pretty good. (Last thing I tried to transcribe was *Making Our Dreams Come True* from memory. I'd say it was 85-90% right compared to the sheet music.)

I compare to the previous note. Also I make reference not to the tonic (not root) of the key, but to what I think is the surrounding chord.

That second reference to the chord is really important. In homophonic music melody is often just a series of broken chord tones with various non-chord tones added. If you can tell what the chord is and if you have a good knowledge of typical harmony changes, it can help you figure out the melody.

I think my ear improved a lot by singing along to drills on the rule of the octave (major and minor.) It got my ear tuned into the sound of fundamental diatonic harmony. Another good thing is solfege patterns like @Albrecht Hugli recommends. For me `DO TI DO`, `DO RE MI`, `SOL FA MI`, and `DO MI SOL` and the super important patterns.

Having made the point about homophonic music and diatonic harmony you should be aware that a lot of pop/rock music does not use that texture. The melody can often "contradict" the chords. When it does there is a good change the melody is following very simple scale patterns with probably the focus on the tonic or another tonally strong degree of the scale. Try testing whether the melody is using a pentatonic scale. It has a kind of natural resonance and is common.

You may find example of melody centered around stuff like `DO RE MI` or a pentatonic pattern while the chord progression moves through chords that "don't match the melody" for some part of the passage. In my mind it's sort of analogous to a pedal point of oblique motion. One part stays fixed on a stable point (in this case a stable portion of scale) while the other parts move through various tones/chords adding color, direction, and tension. Eventually the diverging parts will come back together. Use that knowledge to test things out when trying to transcribe.

One additional thought. When transcribing you can have passages that play note quickly. Even if the tempo is not fast notes can last only a *fraction of a second*. You might replay something a hundred times trying to hear one elusive, brief note! The issue isn't merely matching a pitch. If each note lasted two seconds, there probably wouldn't be a problem as long as you weren't "tone deaf." The quick change is the problem. One solution is to slow down the recording. Lots of people talk about doing that. But this is also why pattern recognition is so important. When you know common patterns you can test them and see if they match, treating a quick series of notes as single pattern unit.