Hiya, I've got a real conundrum that is wrecking my head and I am hoping there is a guru or 2 hanging around here that can give me some advice.
Background info: (this all works)
I have a scrollpane mc with a number of content items inside. This scrollpane mc also has a set # of pixel padding at the bottom. There are enough content items that the scrollpane mc is taller than the stage. The scrollpane and scrollbar resize to fit the stage height. The scrollbar resizes itself so that it is always .5 of stage.height
Clicking on one of these content items expands it from 100px high to 400px, and the content items below are pushed downward (accordion-style)
**note: I am using FlashLoaded's UltimateScroller, but I think this question is abstract enough that the component isn't really relevant
When I click on one of the content items, I want to have the scrollpane scroll, moving the clicked item to a specific stage height. Say to y:100. I have added 400 pixels of padding to the scrollpane (below the content clips) so that the bottom clip can get close to the y target. Also, I want this system to be dynamic, so that I can add content items in the future. (Basically, what I am after is the functionality of simple anchor tags in html)
So, to do this I need to calculate at what percentage the scrollbar needs to go to to move the clicked clip to the specific ypos. This gets awful tricky for me when the stage is resized and when content items are added (making the scrollpane mc taller)
here is a sample swf that doesnt quite work, but provides a decent visual picture: http://mihaiwilson.com/test/
i see the variables as:
> ypos of the clicked clip
> height of the scrollpane mc (that holds the content clips)
> height of the stage
and the dest is:
> scrollbar percentage (the scrollbar can be set by percentage or by raw y values, but it seems to me percentage makes more sense)
Can anyone give me a tip as to how to calculate these variables to get the percentage that I want? Or if Im doing this the wrong way and other variables should be used? I would be very very grateful..
Im also investigating the potential of using the total # of content items to calculate the percentage..