Help with character facing direction he was just walking in

obliviously right now, after the mc walks he will just go to facing down. how can i make it where he faces the direction he was just looking? and i have a frame in the mc for each direction, like “herostopright”, “herostopleft”, etc. thanks!


onClipEvent (load) {
    walkSpeed = 5;
}
onClipEvent (enterFrame) {
    if (Key.isDown(Key.UP)) {
        _y-= walkSpeed;
        this.gotoAndStop("heroup");
    }
    else if(Key.isDown(Key.DOWN)) {
        _y+=walkSpeed;
        this.gotoAndStop("herodown");
    }
    else if(Key.isDown(Key.RIGHT)) {
        _x+=walkSpeed;
        this.gotoAndStop("heroright");
    }
    else if(Key.isDown(Key.LEFT)) {
        _x-=walkSpeed;
        this.gotoAndStop("heroleft");
    }
    else {
        this.gotoAndStop("herostopdown")
    }

}