PDA

View Full Version : Casting string as a class


duki
11-04-2010, 12:13 AM
Hi. I have 52 symbols in my library each with class names Symbol1, Symbol2, Symbol3, etc. I want to create an array of these classes which will be used to create a random particle effect. How do I cast the var cardNumbers so that the array looks like this:

cardTypes = [Symbol1, Symbol2, Symbol3, etc]

instead of

cardTypes = ["Symbol1", "Symbol2", "Symbol3", etc]

This is what I have written so far...

var cardTypes:Array=new Array();

for(var i:Number = 0;i<52; i++)
{
var cardNumbers:String = "Symbol"+i;
cardTypes.push(cardNumbers);

}

Any help would be much appreciated.

senocular
11-04-2010, 11:43 AM
push:

getDefinitionByName(cardNumbers)

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getDefinitionByName()