I am making a Flash web site for a client and they want it easy to add
or subtract or change case study files. Consequently, I am dynamically
loading external thumbnails for each one so that all they have to do
is drop a new thumbnail image into the directory and it will show up
in the SWF movie on their site.
My problem is scrolling the thumbnails. I have it working for sixteen
of them, but don't know how to code it so that it will work with a
different number. Following is the actionscript code I am using. It
seems to be a math issue that I can't quite grasp.
For the thumbnail container movie frame:
(For this example I've specified a fixed number for the
caseStudiesTotal variable. In the actual working situation, this
variable would be the number of thumbnails in the directory.)
[code]
onClipEvent (enterFrame)
{
var caseStudiesTotal = 16;
// _root.slider refers to the draggable button
yn = -_root.slider._x * (caseStudiesTotal * 0.05109375);
// The number 0.05109375 is used because that results in the number
// 0.8175 when multiplied by 16. I don't know why this works, but it
//does.
setProperty("", _x, (_x + 2.0) - (((_x - yn) * 0.8) * 0.3));
}
[/code]
For the draggable slider button frame:
[code]
this.onPress = function () {
startDrag ("", false, 10, 438, 653, 438);
}
this.onRelease = this.onReleaseOutside = function () {
stopDrag ();
}
[/code]
(You shouldn't need the second code snippet, but I've included it just in case.)
The whole Flash movie is 730 x 558 pixels and the thumbnails scroll
horizontally across the entire 730 pixels, with 9 pixels of padding
between each one and on either end. Each thumbnail image is 69 pixels
wide. The width of the scrollbar area is 643 pixels.
See this graphic:
http://www.toddlininger.com/thumbscroll.gif
It's easy to get the total width of the thumbnail container
[#_of_thumbs * (69 + 9) + 9]; now I need the proper code (preferably
easy to understand) to scroll it based on the width of the thumbnail
container and the scrollbar.
Please let me know if you need any clarification. Thank you in advance
for your help. |