In this article we are trying to make our scrollbar to work horizontally also. Download the files from here and then read below. (FLA is saved with CS4)
I haven't yet added any more functionalety to it and we have just made it to work horizontal also, here is how it looks now:
The changes in the FLA are not very complicated and if you have read my last posts you will find your way fast in the new FLA.
but as far as the .as files, I have now devided the classes into 3 and each one now actually does a seperated work.
ScrollbarBase.as > This class will introduce all the variables and sets the positions of all diffrent elelemts by initializing the class "ScrollbarSetter"
If you have noticed I have changed "private" to "protected" for all of the variables in "ScrollbarBase.as" I did this so that I can have access to them easilly from "Scrollbar.as" later which will extends the base class.
I still don't feel comfortable on when to use private and when protected and which methods will make the codes more capsulated, but I think doing some more work will help me understand which one is a better solution. But for now, protected looks just fine as it gives access to the base variables in the subclass file.
anyway, as you can see I have moved the whole responsibility of organizing of the scrollbar according to it Vertical or Horizontal status to a new class called "ScrollbarSetter.as" and in the constructor function of the base class we will call the new class like this:
setpositions = new ScrollbarSetter(pos, w, h, _controlers, _up, _do, _slider, _sliderBg);
well, I tried to use the "internal" accessory for those variables that "ScrollbarSetter" wanted to use but I just couldn't figure out how to make that work! or anyway, would it be a good idea to use the "internal" at all? anyhow, I just passed the parameters and below is the code for how we have set the position of scrollbar according to the H or V status.
and here is the base class.
The important point is that when you want to put a content under the scrollbar you will actually call the Scrollbar class (This is NOT the same file as my last post, don't mix things up! I'm learning things just like you right now, so although it's said that when a class is written, you don't have to modify it anymore, but that can only happen when you have enough experience on how you should organize the base classes, so I hope soon we will reach that level of professionalism!
but for now, please bear with me.)
as I was saying, you'll call the Scrollbar class from the FLA like this:
var scroll1:Scrollbar = new Scrollbar(myScroll_mc, //instance of the scrollbar on stage
myScroll_mc.bg.width,
myScroll_mc.bg.height,
sampleContentV_mc, //content to be scrolled
"V");
And this is the Scrollbar class which extends the base class. here is the Scrollbar class now:
OK, this should do it for now and the scrollbar now works horizontally also but we need to get our data a bit more organized I think as there are still a lot of dark points in the basic facts of AS3 in my mind.
Maybe it would be worthy if I talk a bit about how super(); works as I had some problem with it when working with it for the first time.
when you are extending another class, you cannot have a complete new constructor function for your subclass and it's a must to use the super() which actually means you are importing the base class constructor function and as you see you need to send the parameters through it like below in our sample:
super(scroller, w, h, theContent, pos);
and after that you can add your other lines of codes... But still knowing this after receiving lots of error messages, I don't know how it worked in the tutorials when I extended a Movieclip and I wrote the constoctur function without using the super(); ! I will try to find an answer for that soon though!
in the next version of the class, I try to get the _up and _do buttons to work also.
Regards,
Hadi

My Flash Lab