there is a way to do this if you know what are the possible
reasons of leaving the frame. I mean if the only way to leave the
frame is to press a particular button, add the code to the button's
listener.
You could also try to attach some code to your desired
frame's parent, for ex:
//PARENT's LISTENER
if(child.currentFrame != someFrame)
{
doSomething
}
There could be planty ways to do it, but it all depends on
your project's architecture.