# Adding functions to dynamically created MC's

**URL:** <https://forum.kirupa.com/t/adding-functions-to-dynamically-created-mcs/165546>\
**Category:** Uncategorized\
**Created:** [October 11, 2005, 10:53pm UTC](https://forum.kirupa.com/t/adding-functions-to-dynamically-created-mcs/165546 "2005-10-11T22:53:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwopitz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jwopitz/32/1556_2.png) [@jwopitz](https://forum.kirupa.com/u/jwopitz)\
**Post date:** [October 11, 2005, 10:53pm UTC](https://forum.kirupa.com/t/adding-functions-to-dynamically-created-mcs/165546/1 "2005-10-11T22:53:23Z")

</div>

I am having trouble accomplishing the following:

```auto

var some_xml:XML = new XML();
some_xml.onLoad = function(success) {
	if (success) {
		var rootNode:Object = some_xml.firstChild;
		for (n = 0; n < rootNode.childNodes.length; n++) {
			_root.createEmptyMovieClip("new_mc" + n, n);
			_root["new_mc" + n]._y = n * 20;
			_root["new_mc" + n].createTextField("text_txt", 10, 0, 0, 100, 15);
			_root["menu_mc" + n].onPress = function() {
//this is what I can't to work.
 loadMovie(rootNode.childNodes[n].attributes.loc, _root.empty_mc);
			};
		}
	}
};
some_xml.load("some.xml");

```

This works fine if I use a number, but as soon as I try to use “n” within the function it throws an error. Would eval do this for me? I haven’t used eval before. Thanks.
