Hi there,
I’m relatively inexperienced at actionscripting and I have to build a timeline based on this one: http://www.learner.org/interactives/dna/history.html
I went through both the sliding and the dragging menu tutorials here, worked beautifully(thanks to those who shared), but need the functionality of the sample above. I found a lovely, elegant solution using arrays which is as near as I could find and hoped to modify it to suit my purposes. I’m using a copy of code which formed the basis of this timeline: http://classic.motown.com/timeline/
I’ve been trying to figure this out for two days and am probably being really silly. My problem is I can’t add my content… I can’t add any content that it will scroll through. Basically, I think I need to declare each section as an instance of the array, section, and then the content_mc will parse through it and display each one whether the appropriate button is clicked or the user slides the pointer to that section.
I’m under pressure to get this done so am happy to consider any solution or alternative approach that will produce results similar to http://www.learner.org/interactives/dna/history.html
Many, many thanks to anyone who looks through this and tries to assist!
Code below:
fscommand(“fullscreen”, “false”);
fscommand(“allowscale”, “false”);
stop();
// set up gutter info
gutterLeft = scrollbarGutter_mc._x+1;
gutterRight = scrollbarGutter_mc._x+(scrollbarGutter_mc._width-_root.scrollbar_mc._width)-1;
// create an array for attaching new sections on our timeline
section = new Array(9);//4
max = _root.section.length;
itemDepth = 1;
for (i=0; i<max; i++) {
// attach new item
root.content_mc.attachMovie(“section”, "section"+i, itemDepth);
curItem = content_mc[“section_”+i];
// put the MC in an array
_root.section* = curItem;
if (i == 0) {
curItem._x = 0;
} else {
curItem._x = content_mc._width+1;
}
itemDepth++;
}
// set the info about the content
contentRight = content_mc._x;
contentLeft = 712-content_mc._width;
// calculate the current percentage of the scrollbar
function scrollBarFunc() {
var percent = (scrollbar_mc._x-gutterLeft)/(gutterRight-gutterLeft);
content_mc._x = percent*(contentLeft-contentRight)+contentRight;
updateAfterEvent();
}
// jump the scrollbar to an area on the gutter that equals the beginning of each section
function contentFunc() {
// is the difference between the goal and the position small?
if (Math.abs(scrollBarGoal-scrollbar_mc._x)<1 || !topNav) {
// if so, position everything where it needs to be and stop
scrollbar_mc._x = scrollBarGoal;
content_mc._x = contentGoal;
// transfer power by turning scrollbar actions off
onEnterFrame = null;
} else {
// otherwise move scrollbar and adjust content
scrollbar_mc._x += (scrollBarGoal-scrollbar_mc._x)/6;
scrollBarFunc();
}
}
function moveContent(s) {
// transfer power - turn topNav actions on
topNav = true;
// where should the content go
contentGoal = contentRight-section[s]._x;
// make sure it’s not off the screen!
if (contentGoal<contentLeft) {
contentGoal = contentLeft;
}
// what percent is that goal?
var percent = -(contentGoal-contentRight)/(contentRight-contentLeft);
// apply that percent to the gutter size to determine the scrollbar’s goal
scrollBarGoal = percent*(gutterRight-gutterLeft)+gutterLeft;
// set up a loop to move the content and scrollbar
onEnterFrame = contentFunc;
}
// don’t use the hand icon
scrollbar_mc.useHandCursor = false;
// handle press event
scrollbar_mc.onPress = function() {
this.startDrag(false, _root.gutterLeft, this._y, _root.gutterRight, this._y);
// transfer power - turn topNav actions off
topNav = false;
dragging = true;
this.onMouseMove = function() {
_root.scrollBarFunc();
updateAfterEvent();
};
};
// handle release event
scrollbar_mc.onRelease = scrollbar_mc.onReleaseOutside=function () {
this.onMouseMove = undefined;
this.stopDrag();
dragging = false;
xSpeed = (newxpos-oldxpos)*RATIO;
};
// set initial variables
FRICTION = .9;
RATIO = .5;
dragging = false;
//
// handle onEnterFrame event
scrollbar_mc.onEnterFrame = function() {
if (!dragging && !topNav) {
oldxpos = this._x;
newxpos = oldxpos+xSpeed;
xSpeed *= FRICTION;
if (newxpos>gutterRight || newxpos<gutterLeft) {
xSpeed *= -FRICTION;
newxpos = oldxpos;
}
this._x = newxpos;
_root.scrollBarFunc();
} else {
oldxpos = newxpos;
newxpos = this._x;
}
};
//
The section mc has one frame, a dynamic text box which outputs the section number, and a line of code mySection=this._name;
Thanks, AM