Michael,
As John said, the player who is away plays first regardless of who is on the green or off.
Lets take the two forms of play separately.
In match play, Player A should play first. If B plays before him, A could recall the shot before taking any action. But, since he hit at the same time, he lost the right to recall. Rule 19-5b says that if two balls in motion strike each other, they are played as they lie and no penalty is incurred. If the two balls were hit simultaneously everything ends there. BUT, if A had hit his ball first and B played while A's ball was in motion from a stroke ON the putting green, B would have been in violation of Rule 16-1f since it was not B's turn to play. B would lose the hole.
In stroke play, A should play first, but there is no penalty if B plays before him. If the two balls struck each other while in motion, it depends on the status of A to B. If A and B are partners, the balls will be played as they lie. If A and B were fellow competitors, B's ball would be played as it lies, but A's ball, which was struck from the putting green would have been deflected by a moving outside agency and the stroke would be canceled and would have to be replayed (Rule 19-1b). Again, if B played after A, B would have been in violation of Rule 16-1f and be penalized 2 strokes.