What would be the point of that? The only point of upcasting is to have things compile with strict typing, and the compiler can't tell what the class is if it's dynamically determined.
Are you talking about dynamic *instantiation*? Then you could use something like this: // Import all classes that may be needed. import mygroup.mypackage.mysubpackage.MyClass; // Set up variables. var packagePath:String = "mygroup.mypackage.mysubpackage"; var className:String = "MyClass"; // Get the class' constructor function. var classFunc:Function = getClass(packagePath, className); // Instantiate a test object. var test:Object = new classFunc(); // Test the instantiation; should output result of MyClass.toString(). trace(test); /** * Returns a class' constructor function, given the package path * and the class' name. * * <p>Classes must be imported or they will not be found. * * @param packagePath path of the package, e.g. [EMAIL PROTECTED] "flash.geom"} * @param className name of the class, e.g. [EMAIL PROTECTED] "Point"} * @return constructor function, or [EMAIL PROTECTED] undefined} */ function getClass(packagePath:String, className:String):Function { var package:Object = getPackage(packagePath); return package[className]; } /** * Returns a class package, given its path. * * @param packagePath path of the package, e.g. [EMAIL PROTECTED] "flash.geom"} * @return class package ([EMAIL PROTECTED] Object} instance), or * [EMAIL PROTECTED] undefined} * @see #getClass */ function getPackage(path:String):Object { var package:Object = _global; var pathArray:Array = path.split("."); for (var i:Number = 0; i < pathArray.length; ++i) { package = package[pathArray[i]]; } return package; } -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of aaron smith Sent: Wednesday, August 23, 2006 8:27 AM To: Flashcoders mailing list Subject: Re: [Flashcoders] Dynamically Upcast to a class in the _global tree? no that is just the usual way of doing it.. I need to be able to dynamically upcast.. like: vart = new _global['somepackage']['someClass'](); something like that.. i can't remeber how to do that.. with prototypes or _global.. On 8/23/06, Hans Wichman <[EMAIL PROTECTED]> wrote: > > Hi, > not sure if this is what you mean but: > > import com.somepackage.HomeView; > var bv:BasicView = getSomeBasicView(); > var newHomeViewHomeView =HomeView( bv ); > > grtz > JC > > > On 8/23/06, aaron smith <[EMAIL PROTECTED]> wrote: > > > > How do I cast to something that is in the _global tree. by that i mean. > > cast > > referencing like this: _global.com.somepackage.SomeClass( var ) or is > the > > _prototype chain? I can't remember... > > > > the situation is this, I have a BasicView class. that needs to > dynamically > > be upcast to other views that would potentially extend it, say a > HomeView > > that extends BasicView.. > > > > say like this: > > > > var bv:BasicView = getSomeBasicView(); > > var newHomeView:_global.com.somepackage.HomeView = > > _global.com.somepackage.HomeView( bv ); > > > > I'm pretty sure it's possible, don't remember how to do it... > > > > thanks.. > > _______________________________________________ > > Flashcoders@chattyfig.figleaf.com > > To change your subscription options or search the archive: > > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > > > Brought to you by Fig Leaf Software > > Premier Authorized Adobe Consulting and Training > > http://www.figleaf.com > > http://training.figleaf.com > > > _______________________________________________ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com