all groups > macromedia flash sitedesign > june 2006 >
You're in the

macromedia flash sitedesign

group:

Help!!



Help!! maleeks
6/29/2006 12:00:00 AM
macromedia flash sitedesign: Hello!
I have designed a time line using 'year' buttons (1940, 1950 etc) to scroll
through to the coresponding year in the time line. This all works great except
my boss wants me to have 'previous decade' and 'next decade' buttons that
scroll through the years one by one.
Re: Help!! Rob Dillon - Adobe Community Expert
6/29/2006 7:54:32 AM
One way to do this would be to put the year button's instance names in
an array. Set a variable to hold the name of the current button's
instance name. As the user moves through the years using the year
buttons, keep the name of the current button in the variable. If the
user uses the next or previous button, look at the position of the
current button's name in the array, do whatever frame change you need to
do to get to the next or previous year, and put the new year's button's
instance name in the variable.

--
Rob
_______
Rob Dillon
Adobe Community Expert
http://www.ddg-designs.com
412-243-9119

Re: Help!! Rob Dillon - Adobe Community Expert
6/29/2006 11:35:17 AM
In a frame actionscript space:

-------------
// create a variable to hold the current button...
var currentButton:String;

// create the array and populate it with the instance names of the
buttons...
var buttonArray:Array = new Array(button1,button2,button3,button4);
var buttonArrayCount:Number = buttonArray.length - 1;

// assign a function for the mouse up event to each button:
for (i in buttonArray) {
buttonArray[i].onRelease = buttonMoveFunction;
}

// when the user selects one of the date buttons...
function buttonMoveFunction() {
currentButton = this;
gotoAndStop(X);
// X is the frame number or label that you want to move to
// I would use frame labels and make a corresponding array to the
label names
}

// the next button, for this example I'm expecting the next button,
instance name to be "nextButton"
nextButton.onRelease = function() {
for (i in buttonArray) {
if((buttonArray[i] == currentButton) && (currentButton !=
buttonArray[buttonArrayCount])) {
currentButton = buttonArray[i + 1];
gotoAndStop(X);
} else if (currentButton == buttonArray[buttonArrayCount]) {
// you're at the end, you could loop back to the beginning if
that's appropriate, if not, just leave out the else if part.
}
}
}

previousButton.onRelease = function() {
for (i in buttonArray) {
if((buttonArray[i] == currentButton) && (currentButton !=
buttonArray[0])) {
currentButton = buttonArray[i - 1];
gotoAndStop(X);
} else if (currentButton == buttonArray[0]) {
// you're at the beginning, you could loop to the end if that's
appropriate, if not, just leave out the else if part.
}
}
}
-----------------

That's all off the top of my head, I haven't tested it, but it should
get you started.

--
Rob
_______
Rob Dillon
Adobe Community Expert
http://www.ddg-designs.com
412-243-9119

Re: Help!! maleeks
6/29/2006 12:57:24 PM
Hi Rob,
Thanks for answering! Unfortunately I'm a bit of a Flash pleb and have no
experience with arrays... do you have any examples of what you mean i.e. code
snippets or something?

Very much appreciated if you can spare the time!

Maleka
AddThis Social Bookmark Button