Copy link to clipboard
Copied
var persona:Array = new Array();
for (var i:int = 1; i <= 26; i++)
{
if (i<10)
{
persona.push("persona0"+i);
}
else
{
persona.push("persona"+i);
}
}
//
var personaclip = persona[4]; //persona04
var personainstance:MovieClip = new personaclip();
addChild(personainstance);
What I'm trying to do here is first create an array of all the 26 clips which are already in the library and set to export to actionscript, persona01 to persona26.
Then I pick number for as the clip to be used, which is persona04. I want to add that to the stage. So I first create the instance of the persona04 clip through personainstance and then add it through addChild.
But the personainstance variable is where I go wrong as I get an error #1007 trying to create an instance on an element which isn't a constructor. How can I make it clear that for the personainstance movieclip I would like to select the persona04 clip form the library? Guess I have to convert the string 'persona04' to the constructor name somehow.
creating dynamic class instances using Strings
-------------------------------------------------------------
var ClassRef:Class = Class(getDefinitionByName("className"));
var classInstance:* = new ClassRef();
addChild(classInstance);
Copy link to clipboard
Copied
creating dynamic class instances using Strings
-------------------------------------------------------------
var ClassRef:Class = Class(getDefinitionByName("className"));
var classInstance:* = new ClassRef();
addChild(classInstance);