# Instantiate Class using String

**URL:** <https://forum.kirupa.com/t/instantiate-class-using-string/228282>\
**Category:** flash\
**Created:** [June 6, 2007, 5:51pm UTC](https://forum.kirupa.com/t/instantiate-class-using-string/228282 "2007-06-06T17:51:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![douglaae](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@douglaae](https://forum.kirupa.com/u/douglaae)\
**Post date:** [June 6, 2007, 5:51pm UTC](https://forum.kirupa.com/t/instantiate-class-using-string/228282/1 "2007-06-06T17:51:44Z")

</div>

In AS2, you could write: attachMovie(“someLibraryItem”, …), and this would create an instance on the \_root accessible by \_root.someLibraryItem. Is this possible using AS3? I know the standard way is to just do: var foo:LibraryItem = new LibraryItem(), but I’d like to be able to create an instance of a class and have its name be defined by a string. I’d like to do this:

root[“circle” + i] = new MovieClip(); //causes a run-time error

I noticed that the following is still legal in AS3:  
trace(root[“circle1”]); //works as expected

Is there any way to do this? I noticed that the “name” property of all DisplayObjects is read-write, but it doesn’t seem that changing the name has any effect on the instance name. Any help would be greatly appreciated!

Andy
