Running code 'on frame exit'?

trying to run some code when leaving the current frame…
I assumed you could use Event.EXIT_FRAME

but for example,

stop();
if(Event.EXIT_FRAME){
trace(“hi”);
}

‘hi’ gets output even though I haven’t exited the current frame (frame 1) ??

how do I achieve this ??