Attacks of opportunity against ranged attacks – order of attacks

Character A is using a ranged weapon while he is within the threatend area of character B. For that reason, character B can make an attack of opportunity against character A.

Question regarding the order of the attacks: The attack of opportunity of character B comes before the ranged attack of character A, right? If the attack of opportunity by character B causes enough damage to kill character A, then character A cannot make the ranged attack anymore, can he?