Hi,
I have a menu with 4 movieclip buttons (movieclips that act as buttons) that when pressed make the timeline jump to a certain frame. The mc buttons have both “onrollover” and “selected” states.
However the timeline also moves on its own, even if no button is pressed.
I need the buttons to assume the “selected” state when the timeline reaches a specific frame (as if the button had been pressed to make the timeline jump there). But I can’t figure out how to do it althought I think it must be quite simple.
If anyone can help me it would be appreciatted. This is the code I’m using (controls the buttons and its on the first frame of the main timeline)
// create an array of all nav buttons in group
var groupinfo:Array = [birds, bears, bats, bunnies];
// create constants to define start and stop of fadein and fadeout sequences
// (fadeout should be exactly the same sequence as fadein, in reverse frame order)
var FADEINSTART:Number = 10;
var FADEINSTOP:Number = 19;
var FADEOUTSTART:Number = 20;
var FADEOUTSTOP:Number = 29;
// create a variable to track the currently selected button
var activebtn:MovieClip;
// doRollOver: start the rollover action or process,
// unless the button is currently selected
function doRollOver() {
if (this != activebtn) {
// if fading out, send to corresponding frame in fadein
if (this._currentframe > FADEOUTSTART && this._currentframe < FADEOUTSTOP) {
this.gotoAndPlay(FADEINSTART + FADEOUTSTOP - this._currentframe);
} else {
this.gotoAndPlay(FADEINSTART);
}
}
}
// doRollOut: start the rollout action or process,
// unless the button is currently selected
function doRollOut() {
if (this != activebtn) {
// if fading in, send to corresponding frame in fadeout
if (this._currentframe > FADEINSTART && this._currentframe < FADEINSTOP) {
this.gotoAndPlay(FADEOUTSTART + FADEINSTOP - this._currentframe);
} else {
this.gotoAndPlay(FADEOUTSTART);
}
}
}
// doClick: 1) save a reference to previously active button, 2) update activebtn,
// 3) turn off previously active, 4) turn on current active
function doClick() {
var prevbtn:MovieClip= activebtn;
activebtn = this; // update pointer to current selection
prevbtn.onRollOut(); // return previously selected to normal
this.gotoAndStop(FADEINSTOP); // change appearance of selected mc
}
// assign functions to each event for each button in the group
function init() {
for (var mc in groupinfo) {
groupinfo[mc].onRollOver = doRollOver;
groupinfo[mc].onRollOut = doRollOut;
groupinfo[mc].onRelease = doClick;
}
}
init();
Code used from here: http://flash-creations.com/notes/actionscript_groupofbuttons.php