On Apr 16, 2007, at 4:45 PM, Matt Maher wrote:

I bet this is easy.

 I have "MainView" as a string and I need to create an object of that
 type... for example

 var myObject:Object = new GetObjectFromString("MainView");

 I know, that line of code is a mess. Got any help for me?! Thanks!!


I ran into something like this the other day. "getDefinitionByName()" is what you're looking for.

// import utils
import flash.utils.*;

// our target class
import mx.controls.Button;


var className = "Button";

var theClass:Object = flash.utils.getDefinitionByName("mx.controls." + className);
var theNewObject = new theClass();



I only messed with it long enough to get what I needed out of it so others here might be able to chime in. As far as I was able to tell, you still need the full path ("mx.controls." in this example).


john

Reply via email to