# Control / detect a dynamic instance mc

**URL:** <https://forum.kirupa.com/t/control-detect-a-dynamic-instance-mc/28516>\
**Category:** Uncategorized\
**Created:** [August 14, 2003, 4:37pm UTC](https://forum.kirupa.com/t/control-detect-a-dynamic-instance-mc/28516 "2003-08-14T16:37:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ogden](https://avatars.discourse-cdn.com/v4/letter/o/bcef8e/32.png) [@ogden](https://forum.kirupa.com/u/ogden)\
**Post date:** [August 14, 2003, 4:37pm UTC](https://forum.kirupa.com/t/control-detect-a-dynamic-instance-mc/28516/1 "2003-08-14T16:37:06Z")

</div>

ok - i have a menu that is created from an xml file. all seems to be working well with that. i want the instance of the menuElement\_mc to change when the user clicks on one of them - ok that works. BUT when a user clicks on another instance of the menuElement\_mc i want that instance to change to the ON state and any other previously click item to go to the OFF state.

here is the code that loads the xml:  
[AS]function assembleMenu() {  
for (var i = 0; i\<myarray.length; i++) {  
duplicateMovieClip(menuElement\_mc, “menuElement\_mc”+i, i);  
thistimeline[“menuElement\_mc”+i].\_y = menuElement\_mc.\_y+(offset_i);  
//offset  
thistimeline[“menuElement\_mc”+i].header = myarray_.header;  
thistimeline[“menuElement\_mc”+i].link = myarray\*.link;  
}  
menuElement\_mc.unloadMovie();  
//   
contentheight = this.\_height;  
//   
if (contentheight\>containerheight) {  
\_parent.scrollbar1\_mc.\_visible = true;  
\_parent.scrollbar1\_mc.sliderHeight();  
} else {  
\_parent.scrollbar1\_mc.\_visible = false;  
}  
//   
//  
}  
function menuItem(h, l) {  
this.header = h;  
this.link = l;  
}  
//  
//

var myarray = new Array();  
var myXml = new XML();  
myXml.onLoad = function() {  
var head, link;  
for (var i = 0; i\<this.firstChild.childNodes.length; i++) {  
if (this.firstChild.childNodes\*.nodeName != null) {  
head = this.firstChild.childNodes\*.childNodes[1].firstChild.nodeValue;  
link = this.firstChild.childNodes\*.childNodes[3].firstChild.nodeValue;  
myarray.push(new menuItem(head, link));  
}  
}  
assembleMenu();  
};  
myXml.load(\_parent.\_parent.XMLFileToLoad);[/AS]

here is the code for the menuElement:  
[AS]header\_txt.text = header;  
//  
hotspot\_btn.onRelease = function() {  
\_root.results\_mc.\_x = Math.round(\_root.menu\_mc.\_x+325);  
\_root.results\_mc.\_y = Math.round(\_root.menu\_mc.\_y);  
//  
// frame 2 has the ON state for the button  
gotoAndStop(2);  
//  
\_root.results\_mc.loadMovie(\_parent.\_parent.\_parent.NameofResultsPanel);  
//  
// link is the name of the XML file to populate the results panel  
\_root.link = link;  
};  
stop();[/AS]
