I have 3 diagrams with movieclips. In each diagram, when one movieclip is selected, that movieclip opens up in a container, using addChild. The movieclip var names reflect which diagram they are from, ie soc_a1, soc_b1, soc_c1 belong to one diagram , fam_a1, fam_b1, fam_c1 belong to the second diagram, and cross_a1, cross_a2, cross_c1 belong to the third diagram. Each movieclip has 5-6 variations of the movieclip, named like this soc_a1, soc_a1_zon, soc_a1_sem, soc_a1_tou, soc_a1_mov, which can each be revealed through different buttons. So here is my code for one of these button, ‘gr_options.nor_btn’ which will reveal the normal state of the movieclips (i.e. soc_a1 or fam_b1 etc), depending on which movieclip is currently shown in the container.
So my question is if anyone has suggestions to simplify my code? I have hundreds of movieclips to add, so this code is way to long. I think this should be done using a for loop, but I cannot figure it out as my var names contain both letters and numbers. I have also looked into Arrays, however I cannot seem to get them to work with movieclips loaded dynamically (without instance names).
Please let me know if further explanation is needed.
gr_options.nor_btn.addEventListener(MouseEvent.MOUSE_DOWN,view_greeting_normal);
function view_greeting_normal(event:MouseEvent):void {
gr_options.greeting_views.text = "Vector Animation";
if (container.contains(fam_c5_zon)){
container.removeChildAt(0);
container.addChild(fam_c5);
}
else if (container.contains(fam_c5_spa)){
container.removeChildAt(0);
container.addChild(fam_c5);
}
else if (container.contains(fam_c5_tou)){
container.removeChildAt(0);
container.addChild(fam_c5);
}
else if (container.contains(fam_c5_mov)){
container.removeChildAt(0);
container.addChild(fam_c5);
}
else if (container.contains(fam_d5_zon)){
container.removeChildAt(0);
container.addChild(fam_d5);
}
else if (container.contains(fam_d5_spa)){
container.removeChildAt(0);
container.addChild(fam_d5);
}
else if (container.contains(fam_d5_tou)){
container.removeChildAt(0);
container.addChild(fam_d5);
}
else if (container.contains(fam_d5_mov)){
container.removeChildAt(0);
container.addChild(fam_d5);
}
else if (container.contains(soc_b5_zon)){
container.removeChildAt(0);
container.addChild(soc_b5);
}
else if (container.contains(soc_b5_spa)){
container.removeChildAt(0);
container.addChild(soc_b5);
}
else if (container.contains(soc_b5_tou)){
container.removeChildAt(0);
container.addChild(soc_b5);
}
else if (container.contains(soc_b5_mov)){
container.removeChildAt(0);
container.addChild(soc_b5);
}
else if (container.contains(soc_e5_zon)){
container.removeChildAt(0);
container.addChild(soc_e5);
}
else if (container.contains(soc_e5_spa)){
container.removeChildAt(0);
container.addChild(soc_e5);
}
else if (container.contains(soc_e5_tou)){
container.removeChildAt(0);
container.addChild(soc_e5);
}
else if (container.contains(soc_e5_mov)){
container.removeChildAt(0);
container.addChild(soc_e5);
}
else if (container.contains(cross_c5_zon)){
container.removeChildAt(0);
container.addChild(cross_c5);
}
else if (container.contains(cross_c5_spa)){
container.removeChildAt(0);
container.addChild(cross_c5);
}
else if (container.contains(cross_c5_tou)){
container.removeChildAt(0);
container.addChild(cross_c5);
}
else if (container.contains(cross_c5_mov)){
container.removeChildAt(0);
container.addChild(cross_c5);
}
}