-
Scrollbar issues
I decided I would try and learn this one without reading any tutorials and see how far I could get.
So far I can get it to almost work using this code:
private function startScroll():void {
//proportion = theText.infotextmc.height / theText.textMask.height;
scrollHere = scrollThumb.y - theText.textMask.y;
TweenMax.to(theText.infotextmc, 0.5, { y:scrollHere});
}
My movieclips are:
theText.infotextmc - this holds the text as its dynamic and uses the autosize code
theText.textMask - the masker always a predifined size and never changes
scrollThumb - this is the scrollbar handle
scrollRail - This is the rail of the scrollbar
Now what happens is that it actually does scroll from 0 but not to the maximum of the textfield. Obviously by looking at the code it doesn't know the height of the text field to actually scroll by. Its only scrolling to the number provided by the scrollHere var. I just cant work out how to feed this info in in a correct formula - i did try with the proportion var but with no luck
Thanks in advance
Mark
-
First work out the max scroll distance
var scrollDist:int = theText.textMask.height - theText.infotextmc.height;
Then work out the proportion of that you want to scroll to
var scrollPerc:Number = scrollThumb.y/scrollRail.height;
Then multiply them and that's your scrollDistance
var scrollHere:int = scrollDist * scrollPerc;
TweenMax.to(theText.infotextmc, 0.5, { y:scrollHere});
I think this is correct, though without testing I can't be %100 sure. It depends on everything having 0 y as default (otherwise you need offsets.
Also if this were me I wouldn't use tweenMax. I would put a mouseMove listener that's activated when you press the scroll handle then removed on a stage release.
-
Ahhh I see. There are definately offsets involved as everything is generated dynamically and then positioned by references and ifs.
Thanks for the nod in the right direction. Will post back with the results.
-
Thanks for your help. Ive been battling to get the offset to work I just cant seem to grasp it. Heres where im at:
var scrollDist:int = theText.infotextmc.height - theText.textMask.height;
var scrollPerc:Number = scrollThumb.y / scrollRail.height;
var scrollHere:int = scrollDist * scrollPerc + scrollThumb.height;
var offset:Number = scrollHere - theText.infotextmc.height;
Thanks again for your help in advance.
Mark
-
I think I might have realised by im having so much trouble. The main reason I can see that the text field and mask reside in a movie clip giving there y's a value of 0.
The scroll handle isnt and has a value that reflects where it is positioned. They dont correlate!
Ill report back when I have sorted this out.
-
It all works now - brilliant. It has made me now tidy up the rest of teh positioning references as I was making things too complicated.