我以前做过这个,但是我记不清语法了。
我的代码(简化版):
function createText(clazz:Class)
{
var font:Font = new clazz(); //throws Instantiation attempted on a non-constructor.
}
我相信可以不使用getQualifiedClassName来完成,但已经很久没用了。非常感谢任何帮助。
我以前做过这个,但是我记不清语法了。
我的代码(简化版):
function createText(clazz:Class)
{
var font:Font = new clazz(); //throws Instantiation attempted on a non-constructor.
}
我相信可以不使用getQualifiedClassName来完成,但已经很久没用了。非常感谢任何帮助。
package
{
import flash.display.Sprite;
public class ClassTest extends Sprite
{
function ClassTest()
{
makeObject(Object);
makeObject(Sprite);
makeObject(null);
}
private function makeObject(type:Class):void
{
trace(typeof type);
var obj:* = new type();
trace(typeof obj);
trace("");
}
}
}
object
object
object
object
object
TypeError: Error #1007: Instantiation attempted on a non-constructor.
at ClassTest/makeObject()
at ClassTest()
var clazz:Class = this.yourLoader.contentLoaderInfo.applicationDomain.getDefinition("yourClassName") as Class;