# Cast string as function

**URL:** <https://forum.kirupa.com/t/cast-string-as-function/288447>\
**Category:** Uncategorized\
**Created:** [May 15, 2009, 7:16pm UTC](https://forum.kirupa.com/t/cast-string-as-function/288447 "2009-05-15T19:16:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![activa](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@activa](https://forum.kirupa.com/u/activa)\
**Post date:** [May 15, 2009, 7:16pm UTC](https://forum.kirupa.com/t/cast-string-as-function/288447/1 "2009-05-15T19:16:50Z")

</div>

I want to have a loader function that passes the loaded data to the correct function. So I can do this:

```auto
loadFile ('nodeText.txt', 'makeNodeArray' );

function loadFile (loadFile:String, sendTo:String):void {
	var loader:URLLoader = new URLLoader();
	loader.addEventListener (Event.COMPLETE, playlistLoaded);
	function playlistLoaded (e:Event):void {
		switch (sendTo) {
			case 'makeNodeArray' :
				makeNodeArray (e.target.data);
				return;
			case 'makeLinkArray' :
				makeLinkArray (e.target.data);
				return;
		}
	}
	loader.load (new URLRequest(loadFile));
}

```

Is there any way to type the second variable to avoid the clumsy switch routine, like so:  
Function (sendTo) ();
