all groups > flash actionscript > december 2005 >
You're in the

flash actionscript

group:

Creating class objects on the fly



Creating class objects on the fly t3rm1n4l
12/27/2005 11:50:03 PM
flash actionscript: I'm trying to create custom classes on the fly at random. for instance if i
have ball, square, triangle objects i want to spawn them at random

var newObj = new Ball or new Square, i could do a random number and then a
switch statement but i'm upwards of 20 diff classes now. Is there some nifty
way i can say var newObj = eval("new " + randomObj + ()"); random object being
a string containing the class name.
Re: Creating class objects on the fly NSurveyor
12/28/2005 12:36:30 AM
var class_str = "Square";
var c_func = eval(class_str);
AddThis Social Bookmark Button