# Problem with concatenating names

**URL:** <https://forum.kirupa.com/t/problem-with-concatenating-names/291030>\
**Category:** flash\
**Created:** [June 23, 2009, 9:15pm UTC](https://forum.kirupa.com/t/problem-with-concatenating-names/291030 "2009-06-23T21:15:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sounddevisor](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@sounddevisor](https://forum.kirupa.com/u/sounddevisor)\
**Post date:** [June 23, 2009, 9:15pm UTC](https://forum.kirupa.com/t/problem-with-concatenating-names/291030/1 "2009-06-23T21:15:05Z")

</div>

Here’s the problem:

I have written a simple mp3 player as a custom class, SimpleMp3Player. All it does is load and play a single mp3, which is passed in to the constructor.

My main class has a function **LoadMedia()** which creates _n_ instances of this class, names them _player\_1_ through _player\_n_ and places them in various locations.

I am also trying to write a **RemoveMedia()** function to get rid of all the instances. I can brute-force remove them all by hard coding _removeChild(player\_1)_, \*removeChild(player\_2) \*etc. through _removeChild(player\_n)_.

But of course, I would much rather use a loop to do this. I tried this:[INDENT]for (var i:int = 0; i\<21; i++) {  
removeChild(getChildByName([“player\_”] + (i+1)));  
}  
[/INDENT]but I get this error:  
TypeError: Error #2007: Parameter child must be non-null.  
at flash.display.DisplayObjectContainer/removeChild()

I have tried every variation of the syntax I can think of with no success. What am I doing wrong here?
