Marsoups
06-05-2008, 09:42 AM
Hi all,
Let's say I have two classes :
package {
public class B1 {
function B1() {
trace("CLASS B1 INSTANTIATED");
}
}
}
package {
public class B2 {
function B2() {
trace("CLASS B2 INSTANTIATED");
}
}
}
Now in my main movie, I want to create an instance of one of these classes, but I wish to do so dynamically, by referring to the name of the class in a variable, if you catch my drift. So let's say I have an array with the names of the classes :
var number = 1;
var classname = "B"+number;
var newinstance = new classname;
How can this be achieved ? I get this error if I define classname as a class:
TypeError: Error #1034: Type Coercion failed: cannot convert "B1" to Class.
at classtest_fla::MainTimeline/classtest_fla::frame1()
Let's say I have two classes :
package {
public class B1 {
function B1() {
trace("CLASS B1 INSTANTIATED");
}
}
}
package {
public class B2 {
function B2() {
trace("CLASS B2 INSTANTIATED");
}
}
}
Now in my main movie, I want to create an instance of one of these classes, but I wish to do so dynamically, by referring to the name of the class in a variable, if you catch my drift. So let's say I have an array with the names of the classes :
var number = 1;
var classname = "B"+number;
var newinstance = new classname;
How can this be achieved ? I get this error if I define classname as a class:
TypeError: Error #1034: Type Coercion failed: cannot convert "B1" to Class.
at classtest_fla::MainTimeline/classtest_fla::frame1()