Hi all,
I wrote this code for a nav system where when one of the buttons is pressed that will slide to out of the list, then if another button is pressed that will slide out of the list and the first button will slide back to it’s position in the list, and so on. Its the sort of thing I seen around so nothing special, but I’m not too sure about the way I’ve done it and wondered if someone could advise if I’ve done it a really stupid way and if there is a better solution.
Thanks in advance.
stop();
//
//Variables///////////////////
//
var btn_spacing = 20;
scroll_speed = 4.2;
var btnFin = 250;
var portOpen = null;
var openBtnY = null;
//
//XML loading
my_xml = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success) {
if (success) {
DisplayBands();
} else {
trace("XML Not Loaded");
}
};
my_xml.load("images.xml");
//
//xml function //////////////////////////////
function DisplayBands() {
one = my_xml.firstChild.childNodes;
for (i=0; i<one.length; i++) {
two = one*;
bandBtn = holder_mc.attachMovie("btn_mc", "btn_mc"+i, i+1);
bandBtn._y = btn_spacing*i;
bandBtn.id = two.attributes.name;
bandBtn.yid = bandBtn._y;
bandBtn.txt_txt.text = bandBtn.id;
bandBtn.onRollOver = bandBtn.onPress=function () {
this.txt_txt.textColor = 0xc0240e;
};
bandBtn.onRollOut = function() {
this.txt_txt.textColor = 0x505050;
};
bandBtn.onRelease = function() {
btnSlide(this, openBtn, openBtnY);
openBtnY = this.yid;
openBtn = this;
};
}
}
//
// this is the bit I'm not too sure about.
function btnSlide(btn, btnOpen, btnOpenY) {
this.createEmptyMovieClip("tracker", 1000);
tracker.onEnterFrame = function() {
btnOpen._y += (btnOpenY-btnOpen._y)/scroll_speed;// if there is a btn out of the list this is it moving back up
btn._y += (btnFin-btn._y)/scroll_speed;
if (btn._y>=btnFin && btnOpen._y<=btnOpenY) {
btn._y == btnFin;
btnOpen._y == btnOpenY;
delete this.onEnterFrame;
removeMovieClip(tracker)
}
};
}