In order to flank, you must fulfill two criteria:
1) You must be able to attack the flanked creature.
2) You must be adjacent to the enemy with an ally adjacent to it on the opposite side or corner.
In other words, yes, you still have to be adjacent to flank even if you are armed with a ranged weapon.