Question
getDefinitionByName
Hi all,
I have a library of custom classes and I want to use an array of strings to create instances of them. The array takes the form of:
var arr:Array = [["Class1","Label1"],["Class2","label2"]...["Classn","Labeln"]];
I then loop through the array and create instances like this:
var classRef:Class = getDefinitionByName("com.domain.application.library."+libData[0]) as Class;
var obj:Object = new classRef();
This is what I have seen in the help files and tutorials but when this runs I get ReferenceError: Error #1065: Variable Class1 is not defined.
I was about to give up and then found that if I add 'new Class1();' before the loop then two instances are created, one for the manual call and one for the getDefinitionByName call. Can anyone explain what is happening here and what I could do to make this work without having to manually create an instance first?
Cheers for any help
I have a library of custom classes and I want to use an array of strings to create instances of them. The array takes the form of:
var arr:Array = [["Class1","Label1"],["Class2","label2"]...["Classn","Labeln"]];
I then loop through the array and create instances like this:
var classRef:Class = getDefinitionByName("com.domain.application.library."+libData[0]) as Class;
var obj:Object = new classRef();
This is what I have seen in the help files and tutorials but when this runs I get ReferenceError: Error #1065: Variable Class1 is not defined.
I was about to give up and then found that if I add 'new Class1();' before the loop then two instances are created, one for the manual call and one for the getDefinitionByName call. Can anyone explain what is happening here and what I could do to make this work without having to manually create an instance first?
Cheers for any help