# Reference class problem

**URL:** https://forum.kirupa.com/t/reference-class-problem/319877
**Category:** flash
**Created:** [March 7, 2011, 5:05pm UTC](https://forum.kirupa.com/t/reference-class-problem/319877 "2011-03-07T17:05:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![TurboTuTone](https://avatars.discourse-cdn.com/v4/letter/t/6f9a4e/32.png) [@TurboTuTone](https://forum.kirupa.com/u/TurboTuTone)
#### Post date: [March 7, 2011, 5:05pm UTC](https://forum.kirupa.com/t/reference-class-problem/319877/1 "2011-03-07T17:05:35Z")

</div>

Hello everyone,

Im wondering if anyone can help me out with a little problem im having.  
Ive been working on a small game and noticed i was re-using the same code several times so i decided to see if i can combine the code.

Heres my old code, which worked:

```auto

        public function show_loader() {
            loader_screen = new loader(this);
            loader_screen.init_loader();
            loader_screen.addEventListener( CustomEvent.PARAM_TYPE, custom_handler );
            addChild(loader_screen);
        }
        
        public function hide_loader() {
            if (loader_screen) {
                removeChild(loader_screen);
                loader_screen.removeEventListener( CustomEvent.PARAM_TYPE, custom_handler );
                loader_screen = null;
            }
            return;
        }
        
        public function show_mainmenu() {
            mainmenu_screen = new mainmenu(this);
            mainmenu_screen.init_mainmenu();
            mainmenu_screen.addEventListener( CustomEvent.PARAM_TYPE, custom_handler );
            addChild(mainmenu_screen);
        }

        public function hide_mainmenu() {
            if (mainmenu_screen) {
                removeChild(mainmenu_screen);
                mainmenu_screen.removeEventListener( CustomEvent.PARAM_TYPE, custom_handler );
                mainmenu_screen = null;
            }
            return;
        }

```

Thats only 2, i use it more often, basically to show and clear all the stages of the game.  
So when i narrowed it down to a single function for all screens this is what i got:

```auto

        public function show_screen(ref:String) {
            trace(ref);
            var GetName:String = ref;
            var ClassName:Class = getDefinitionByName(GetName) as Class;
            this[ref+"_screen"] = new ClassName(this) as Class;
            this[ref+"_screen"].init_loader();
            this[ref+"_screen"].addEventListener( CustomEvent.PARAM_TYPE, custom_handler );
            addChild(this[ref+"_screen"]);
        }

```

The passed variable to the function is the name of the class. However i get an error:

```auto
ReferenceError: Error #1065: Variabele loader is not defined.

```

Ive tried googling the error but havent found anything yet that solves the problem.

If anyone can help me with this would be great. If you need more information i can post whatevers needed.

Thanks,  
Turbo
