# Array probs

**URL:** <https://forum.kirupa.com/t/array-probs/8369>\
**Category:** Uncategorized\
**Created:** [November 19, 2002, 4:58pm UTC](https://forum.kirupa.com/t/array-probs/8369 "2002-11-19T16:58:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jez](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jez](https://forum.kirupa.com/u/jez)\
**Post date:** [November 19, 2002, 4:58pm UTC](https://forum.kirupa.com/t/array-probs/8369/1 "2002-11-19T16:58:37Z")

</div>

Hope someone can help - it’s probably simple but I can’t get my head around it!! I have taken this script from a tutorial which uses a scrollbar and buttons to control a number of sections created by an array. I have an empty movie clip called ‘content\_mc’ on the main stage, linked to which is a movie clip with the identifier ‘section’.

The tutorial doesn’t explain and I can’t figure out how to actually add different content into the 5 sections.

// 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(5);  
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;  
}  
};

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 19, 2002, 7:42pm UTC](https://forum.kirupa.com/t/array-probs/8369/2 "2002-11-19T19:42:41Z")

</div>

Am getting unexpected file format when trying to open the FLA. ☹
