If $Y=$ Spec$A$ is an affine scheme and $D(f)\subseteq Y$ (with $f\in A$) is a distinguished open, I want to show that $(D(f),\mathscr O_{Y|D(f)})$ is an affine scheme. Below there is my attempt of proof, but I've found a little problem, please help me to fix it.
Preliminary notations
If $(X,\mathscr O_X)$ and $(Y,\mathscr O_Y)$ are two schemes then a morphism between them is simply a morphism of locally ringed spaces $(\varphi, \varphi^{\flat})$.
$\varphi: X\rightarrow Y$ is a continuous map and $\varphi^{\flat}: \mathscr O_Y\rightarrow{\varphi_{\ast}\mathscr O}_X $ is a morphism of sheaves (of rings) on $X$ such that the corresponding map (by adjunction) $\varphi^{\#}:{\varphi^{-1}\mathscr O}_Y\rightarrow \mathscr O_X$ has the property that the induced map on stalks $\varphi_x^{\#}:\mathscr O_{Y,\varphi(x)}\rightarrow \mathscr O_{X,x}$ is a local homomorphism of local rings for every $x\in X$. Practically to give a morphism of schemes I can exhibit a couple $(\varphi, \varphi^{\flat})$ or, in alternative, a couple $(\varphi, \varphi^{\#})$ (with the above notations) but in both cases the map $\varphi_x^{\#}$ should be a local homomorphism.
Data: $A$ is a ring, $Y=$ Spec$A$ and $X=$ Spec$A_f$ with $f\in A$. Clearly $\mathscr O_Y$ and $\mathscr O_X$ are the relative structure sheaves.
Claim: $(D(f),\mathscr O_{Y|D(f)})\cong (X,\mathscr O_X)$
My proof: By an important fact from commutative algebra we know that $X$ is homeomorphic to $D(f)$ by $\varphi$; this homeomorphism $\varphi$ is induced by the canonical map $A\rightarrow A_f$. Now I will show a map $\psi_x:\mathscr O_{Y,\varphi(x)}\rightarrow \mathscr O_{X,x}$ that is an isomorphism of local rings for any $x\in X$. Then we have finished because we can say that exits a map $\varphi^{\#}$ such that $\varphi^{\#}_x=\psi_x$ for any $x\in X$.
Since $\mathscr O_{Y,\varphi(x)}=A_{\varphi(x)}$ (remember $x$ is a prime ideal) and $\mathscr O_{X,x}=(A_f)_x$, the isomorphism $\psi_x$ is the obviuous one.
The problem: Is it enough to give the maps $\varphi^{\#}_x=\psi_x$ at level of the stalks? Who does ensure that once $\psi_x$ is given for every $x$, does exist $\varphi^{\#}$ such that $\varphi^{\#}_x=\psi_x$?
Edit:
For a simpler proof, maybe, I should use the following fact

I can take the identity of $A_f$ (it represent the global section of $X$ and $Y$) and then show that the corresponding map between $X$ and $Y$ is an isomorphism of schemes.