About general approaches and outlines

(warning: hobbyist coder)

Maybe it’s kind of hard to search for but it seems the basic outline of game code isn’t something that’s asked about a lot. Understandably people are more concerned with niggling little problems here and there but it’s actually something I probably should have cleared up a long time ago.

I think my approach to making a game in flash works but I kind of question its effeciency and was wondering if anyone could share their approach. This is basically the set up I’ve been using (in the IDE), I’m just commenting the general areas…

//key booleans
//universal variables (save games, current level, class variables)
var map_01 = new map_01_class;

main_menu();
function main_menu(){
    var main_menu = new main_menu_c;
    addChild(main_menu);

    //mouse listeners for menu items, "options" and "start game"

    function start_game(e:MouseEvent):void {
        //remove menu mouse listeners.
        removeChild(main_menu);
        main_game_play(map_01);
    }
}

function main_game_play(map_name){

    addChild(map_name);

    var various_lists:Array = [];

    //game variables (player health, story flags)

    addEventListener(Event.ENTER_FRAME, update);

    function update(update(e:Event){
        //per-frame code
        //for loops (AI, collisions and things)
        //for loops (adding, changing and deleting things from lists)
        //if this key bool = true, then move/attack.
        //etc.
    }

    function end_level(){
        removeChild(map_name);

        //clear array lists, remove other children.
        //remove "update" listener.
        //call cut-scene function...
    }
}

//key down and up listeners, etc.

As you might guess I don’t use a lot of classes (and I’m not the kind of guy that wants to blit all the images when I can just use MovieClips) so the only thing not handled here are some object properties (velocity, health, etc).

The basic question is this:
If I call Function B from inside Function A, then will any reference/memory space to Function A remain even if all the variables of Function A are never dealt with again?

I didn’t think about it at first but it’s kind of worrisome because in one game I’d like to go from level to cut-scene to level and if “main_game_play” calls a cut scene and then another level (“main_game_play” has a parameter saying what level it is) aren’t they becoming nested somehow? I’m not sure the functions/levels are supposed to appear sequentially like that.

I imagine it’d be better to have one function switching in and out children that it calls, but I’m having trouble imagining it. A single function in the main document that adds and deletes level children after a “function quit” return? Anyone willing to share their set up?

Any help appreciated.