Help! Back to last visited frame

Hi;

How could i write a code that allow me back to the last visited frame?

For example;

currently i m in frame 5, I click on a button that will bring me to frame 10, how could i have a back button in frame 10, so that it will bring me back to frame 5?

I do consider about the following code

ActionScript Code:
[LEFT]
[FONT=Courier New]on COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR][/FONT]
[FONT=Courier New]traceCOLOR=#000000[/COLOR];[/FONT]
[FONT=Courier New]prevFrameCOLOR=#000000;[/COLOR][/FONT]
[FONT=Courier New]traceCOLOR=#000000[/COLOR];[/FONT]
[FONT=Courier New]stopCOLOR=#000000[/COLOR];[/FONT][FONT=Courier New][COLOR=#000000]}[/COLOR][/FONT]
[FONT=Courier New][/FONT] [/LEFT]

but this will bring me to frame 9, which is incorrect.

I also consider about;

ActionScript Code:
[LEFT][FONT=Courier New]<[/FONT]
[FONT=Courier New]on COLOR=#000000[/COLOR][COLOR=#000000]{[/COLOR][/FONT]
[FONT=Courier New]gotoAndStopCOLOR=#000000[/COLOR][/FONT]
[FONT=Courier New][COLOR=#000000]}[/COLOR][/FONT]
[FONT=Courier New][/FONT] [/LEFT]

but my problem is, the first page could be from frame 4, 3, or 2. Therefore, hope anyone could help on get me back to the last visited frame.

Thank you.