Did you ever get an answer on this? I'm running into the same problem with getClassByName(MyCustomClass) blowing up unless I create a dummy instance of it first. Even when I do create a dummy instance first, it only works the first time I call the getClassByName(MyCustomClass) method. After that, I start getting "ReferenceError: Error #1065: Variable MyCustomClass is not defined" all over again.
Thanks, Paul --- In [email protected], "Brendan Meutzner" <[EMAIL PROTECTED]> wrote: > > Hey Jens, > > Thanks for the help. It's now working (sort of)... > > If I create an instance of a built-in class (such as Button), the > method below works fine. However, if I try creating a custom Class > (eg. MyCustClass which extends from Canvas) like so: > > import custclasses.MyCustClass; > var newComponent:Object = createInstance ("custclasses.MyCustClass"); > > it doesn't work. I get the run-time error message "Variable > MyCustClass is not defined". > > However, if I create a dummy instance of the class in my application > like so: > > import custclasses.MyCustClass; > var dummyMyCustClass:MyCustClass = new MyCustClass(); > > and then create another instance using the createInstance method, it > does work. > > Ideas? > > Thanks, > > Brendan > > --- In [email protected], Jens Halm <[EMAIL PROTECTED]> wrote: > > > > > > > Hi All, > > > > > I'd like to provide a String value which represents the DisplayObject > > > class I want to create dynamically with addChild. Has anyone > > > accomplished this? > > > > You mean like this? > > > > public function createInstance (className : String) : Object { > > var MyClass : Class = getClassByName(className); > > return new MyClass(); > > } > > > > > > Btw.: what I really miss is a method createInstance(args : Array) in > > the Class class, so I could easily provide an arbitrary number of > > constructor arguments not known until runtime, like this: > > > > public function createInstance (className:String, args:Array) : Object { > > var myClass : Class = getClassByName(className); > > return myClass.createInstance(args); > > } > > > > Class.createInstance(args:Array) would be the constructor equivalent > > of Function.apply(scope:Object, args:Array). If I use Function.apply > > after I created an instance the constructor would be called twice > > which would be quite dirty. > > > > Consider this as a feature request... ;) > > > > > > Jens > > www.oregano-server.org > > > -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/

