# Access dynamically added movieclips?

**URL:** <https://forum.kirupa.com/t/access-dynamically-added-movieclips/328385>\
**Category:** flash\
**Created:** [May 13, 2012, 9:53pm UTC](https://forum.kirupa.com/t/access-dynamically-added-movieclips/328385 "2012-05-13T21:53:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![obai](https://avatars.discourse-cdn.com/v4/letter/o/aca169/32.png) [@obai](https://forum.kirupa.com/u/obai)\
**Post date:** [May 13, 2012, 9:53pm UTC](https://forum.kirupa.com/t/access-dynamically-added-movieclips/328385/1 "2012-05-13T21:53:43Z")

</div>

So I have only ever coded in AS2, and I am trying to create a tower-defence sort of game in AS3. In my main class I call this function:

```auto
        private function createGrid():void
        {
            for (var a:int = 0; a < numCols; a++)
            {
                for (var b:int = 0; b < numRows; b++)
                {
                    var testBlock:MovieClip = new block();
                    testBlock.name = "block_" + a + "_" + b;
                    testBlock.x = a * 20;
                    testBlock.y = b * 20;
                    addChild(testBlock);
                }
            }
        }

```

That creates a grid on my main stage which works fine. Each block traces it’s name when you click it, all saying “block\_x\_y” relatively, for example “block\_3\_4”, x being the column they are in and y the row, (24 columns, 21 rows). The problem I run into is trying to do ANYTHING with the movieclips added dynamically, in AS2 I could just use:

```auto
_root["block_"+currentX+"_"+currentY].wall

```

“Wall” is a boolean each block has, so I’m trying to get the simplest things done in AS3 by using a function that I call on mouse cilck of a button:

```auto
        private function LoadLevel(map:Array):void
        {
            trace(root["block_1_1"].x);
        }

```

and sadly I cannot get this to work for the life of me. How can I possibly access or refer to movieclips added during runtime? I get this:

```auto
ReferenceError: Error #1069: Property block_14_11 not found on Main and there is no default value.
    at block/onClickHandler()

```

Every time that I try to trace the object’s name, or X, or any value. I have searched everywhere and all I want is a simple method on accesing these, like using \_root[“block\_1\_1”] was in AS2. I would greatly appreciate some help, as I said I am very new to AS3.
