Smart Function

hey guys I got a quick question … there is a way to tell flash … if certain button is press gotoAndPlay certain FrameLabel …
I want to make that functionality inside of this function…
I already tried make a different function for each button and it works but Im pretty sure has to be a way to make all in the same function ?

anyway here is the function :

function goBackWards():Void { 
   this.onEnterFrame = function ():Void { 
      if (_currentframe <= _totalframes) { 
         prevFrame(); 
      } 
      if (_currentframe == 1) { 
         _root.gotoAndStop("home"); 
         delete this.onEnterFrame; 
      } 
   }; 
}

so this works when I say to my home btn this :

home.onRelease = function ():Void { 
    unloadMovieNum(2); 
    goBackWards(); 
};

so this goes to the frame label “home”

but how about if I want to my button Contact using the same function go to another FrameLabel and Play that MC … like my frame Label “M2”

my btn will be like

contact.onRelease = function ():Void { 
     unloadMovie(2); 
    goBackWards(); 
}

but the thing is how the same function can realise when I press this btn (Contact) and play that Framelabel that in this case will be “M2”
Im thinking that it might be a conditional ? just Im not 100% sure? any help or hint would be greatly appreciated

thanks.