AS3 invoking class from linkage by string

Today I was programming a game and I run over a problem, I had to invoke a Class by its string name.
It can easly be solved by using a switch like:

var className:String = "ClassNameOnTheLibrary1";
var gamePhase:MovieClip;

case "ClassNameOnTheLibrary1":
gamePhase = new Phase1();

case "ClassNameOnTheLibrary2":
gamePhase  = new Phase2();


Now what if you have to have thousands of cases. I had only 10 and found a pretty good solution.

Here it goes:
first import the class getDefinitionByName from flash utils.

import flash.utils.getDefinitionByName;

then you just cast your string as a Class and invoke its constructor:

var ClassDefinition:Class = Class( getDefinitionByName( "ClassNameOnTheLibrary1" ) );
var gamePhase:MovieClip = new ClassDefinition();

Thats it, hope I saved you some time.