Call library movieclips from an array of strings
I have an array of strings. Each string is a name of a class. How can I开发者_运维问答 call the library item with the class name that corresponds to the string in the array?
Thanks in advance
You can use the function getDefinitionByName
, found in the package flash.utils.
Usually the code will look something like this:
var oClass:Class = getDefinitionByName("<name of your class>") as Class;
var instance:Object = new oClass();
You can also cast instance
to a type of your choice:
var myType:SomeType = SomeType(instance);
See this link for reference.
精彩评论