# Syntax Problem for Adding MovieClips Dynamically From the Library onto the Stage

**URL:** https://forum.kirupa.com/t/syntax-problem-for-adding-movieclips-dynamically-from-the-library-onto-the-stage/263128
**Category:** flash
**Created:** [June 12, 2008, 7:41pm UTC](https://forum.kirupa.com/t/syntax-problem-for-adding-movieclips-dynamically-from-the-library-onto-the-stage/263128 "2008-06-12T19:41:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MoOMoOMiLK](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@MoOMoOMiLK](https://forum.kirupa.com/u/MoOMoOMiLK)
#### Post date: [June 12, 2008, 7:41pm UTC](https://forum.kirupa.com/t/syntax-problem-for-adding-movieclips-dynamically-from-the-library-onto-the-stage/263128/1 "2008-06-12T19:41:36Z")

</div>

Hi guys,

I am trying to use the addChild method to add a MovieClip from the library onto the stage. I have a set of MovieClips with classes named: Definition1, Definition2, and so on… up to Definition12.

What I am trying to do is to write a function so that depending on the function parameter (which is a random number generated from 1 to 12), it will load different MovieClips starting with “Definition” followed by the random number. I have something like this but the syntax is incorrect. Can someone please correct me on my syntax? Thanks!!

```auto
private function attachDefinition(random:uint):void {
		var _definition:MovieClip = new ["Definition" + random.toString()];			
			this.addChild(_definition);
		}

```

---

<div class="post-metadata">

### Author: ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)
#### Post date: [June 12, 2008, 8:32pm UTC](https://forum.kirupa.com/t/syntax-problem-for-adding-movieclips-dynamically-from-the-library-onto-the-stage/263128/2 "2008-06-12T20:32:52Z")

</div>

look into getDefinitionByName()… in help (F1) - select AS 3.0, in the language and components reference \> All Packages \> flash.utils package \> functions.

Hope this helps.

---

<div class="post-metadata">

### Author: ![MoOMoOMiLK](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@MoOMoOMiLK](https://forum.kirupa.com/u/MoOMoOMiLK)
#### Post date: [June 13, 2008, 9:53pm UTC](https://forum.kirupa.com/t/syntax-problem-for-adding-movieclips-dynamically-from-the-library-onto-the-stage/263128/3 "2008-06-13T21:53:16Z")

</div>

Works like a charm. Thanks!!!
