[FMX] simplicity

So I don’t know if this has been posted before and if it has I apologize…

I’ve noticed that most of my navigation code seems to be the same across all my projects. Instead of repeatedly typing btn1.onRollOver { blah } and btn2.onRollO ver { blah } etc…I thought about simplifying it as much as possible and came up with this:
[AS]
ext = “.swf”;
navArray = [“home”, “about”, “contact”];
for (nv=0; nv<3; nv++) {
var nav = this[“nav”+nv];
nav.nv = nv;
nav.onRollOver = function() {
navPage = navArray[this.nv];
};
nav.onRollOut = function() {
navPage = “”;
};
nav.onRelease = function() {
if (_root.section != navPage) {
_root.section = navPage;
updatePage();
}
};
}
function updatePage() {
this.container.loadMovie(_root.section+ext);
};
[/AS]
this assumes your nav buttons are named nav0 nav1 nav2 etc and that your loading your content into “container” If you want to add more buttons just add them to navArray and increase the nv<3 to whatever.