View Full Version : Instantiate class by variable?
arandomdan
June 25th, 2007, 12:42 AM
I need to instantiate a class based on a variable, how can this be done?
Dazzer
June 25th, 2007, 12:50 AM
var myClass:Class = object.constructor;
var something = new myClass();
should work unless someone corrects me.
McGuffin
June 25th, 2007, 12:50 AM
you need a import your class and instantiate a version of it so it compiles with your swf:
import pack.age.CustomClass;
CustomClass();
and then anywhere else in your movie, you need this:
import flash.utils.getDefinitionByName;
var className:String = "CustomClass";
var classReference:Class = getDefinitionByName("pak.age."+className) as Class;
var classInstance:Object = new classReference();
Should work :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.