Note that if $A$ is compact, then it is bounded and therefore, $\mathrm{d(x,a)}$ is finite. This could fail if $A$ were only closed.
By definition,$$\mathrm{d(x,A)=\inf\{\mathrm{d(x,a)}: a\in A\}}$$
Therefore, if $\mathrm{d(x,a)}=\alpha$, for any $\epsilon>0$, there exists $a_{\epsilon} \in A$ such that $$\alpha \leq d(x,a_{\epsilon})<\alpha+\epsilon$$
Now take $\epsilon=\frac{1}{n}$ and you will get a sequence in $A$ and because $A$ is compact and therefore closed, the limit must be in $A$.
Therefore, $\lim_{n\to \infty}{a_n}=a_* \in A$ and $$\lim_{n\to \infty}\mathrm{d(x,a_n)}=\mathrm{d(x,\lim_{n\to \infty}a_n)}=\mathrm{d(x,a_*)}$$
The second equality holds because metric is continuous in both components.