the single-letter MenuItem MCs are created by duplicateMovieClip()ping the
first one (element 0: 'menuItem0')
As a button (menuItem) is clicked, it's MC reference is stored in the
As we want 'whichButton' to end up on the far left of the navigation bar
(menuItemBase), we have positions menuItemBase's pivot point (the little
'plus' in the Flash development environment) at the location within the
navigation bar where the pivot point of the selected menuItem MC should end
up at the end of the 'smooth scroll' animation.
To ensure that it looks like we are rotating the 6-item menu, we have
replicated each item: two adjacent rows of 6 items.
To track which item MC was selected and help us switch to its 'twin' when
we need to wrap:
if ((StartX - menuItemBase._x) >= WrapWidth)
each menuItem also carries its own index in an extra 'idx' member variable.
When we need to wrap, we can thus calculate the index of its twin:
var i = whichButton.idx - sectionCount;
and 'jump' to that MC for the remainder of the animation so the user sees a
we set 'whichButton' to 'null' when no animation is going on: either a
selected item is in place or we have not yet selected an item. Of course,
one may use an extra boolean variable instead of this 'messing around' with
'null' MC references, but that's just a matter of taste.
How did we build this up?
First we constructed the duplication of menuItem's. (or better: copied it
from the relevant flashcoders mail and edit it a bit)
Then we added the function which is caaled by any of the dupe'd menuItem's
when the button inside the menuItem MC is clicked and released.
Next we edited the basic formula to do the 'smooth scrolling. WITHOUT the
wrapping, so we could see where our code would mess up; of course we
switched a few 'minus this' and 'plus that' items around before it actually
looked anywhere near smooth scrolling.
Lastly the 'wrapping around' code was added. Granted, this code had been
anticipated from the start, but we had better get the basic moves working
properly before engaging this piece of ActionScript.
Note that we have a bit complex coe to determine when the selected item
has reached its final destination: we calculate the distance to the desired
final destination (delta) and check if it is within a 2 'twips' range. Why
do we do it like that? Yeah, we should've checked for a +/- 1 'twip' (1/20th
of a pixel) range, but I thought about that only when I was already typing
this test and didn't feel like editing and republishing the sample SWF again
;-) Anyway: we use a 'tolerance' of a few twips as Flash might not position
the item exactly on the desired location. The item might end up one twip
removed from the desired destination. So we take this 'inaccuracy' into
account in the AS code driving the item/animation.
It might seem a little paranoid, but it's safer than just a straight
whichButton._x == (StartX - menuItemBase._x)
item menuItemBase.menuItem0 already exists on scene in the FLA, so in
order to construct the menu we only need to duplicateMovieClip() it 2*N-1
times, where N is called 'sectionCount' in the code.