[AS3] Add Class to Stage using String

Was working on a project today and stucked and wondering how you can actually place a large number of custom classes in your Library and then call it out via a name that is formed out of a string?

Example: … “mcApple”+number+date

You can actually do it by using the method known as  “Class Reference”.

var yourString:String = “mcName”+”customName”+customData;
var className:Class = getDefinitionByName(yourString) as Class;
var mc:MovieClip = new className();

this.addChild(mc);

See? Doesn’t seem to be too hard and it’s really helpful especially when you’re still very much of a semi-developer/designer and need to access the library dynamically.

References:

You might also like this :

Your Ad Here

Share your thoughts


Comments

  • EMBEDDED82

    Hi, really interesting experiment. I'm searching something ([Experiment] Simulation of Apple Safari’s Top Sites in Flash!)

  • manmeng

    @firdaus : you’re most welcome bro, share your pics yeah, ([Travel] Broga Hill)

  • Alpha Ace

    very helpful info you got here, especially the map. i wil ([Travel] Broga Hill)

  • nash

    hey..thanx so much 4 da info...especially da map..i'm going ([Travel] Broga Hill)

  • firdaus harry

    wow...that place is really amazing.i'm planning to go there ([Travel] Broga Hill)

  • manmeng

    Hey there, Enjoy your trip there and do take extra precaut ([Travel] Broga Hill)

  • Timo K

    Hi all..I m going to Broga Hill tomorrow, to catch the 1st s ([Travel] Broga Hill)

Category

Archives

Links

Admin