Jan 17 2009

Final Scrollbar class V 2.0

Category: Scrollbar,Scrollbar ClassHadi Tavakoli @ 8:23 pm

this post is out of date! check the new scrollbar here: http://www.emstris.com/2009/10/my-super-as3-scrollbar/

Ok, that was a great weekend, I found some time to get back to some old books and once more read about extensions of classes and I founded out that if there's no reason to extend something, why you should force yourself to extend it?! In our last version of scrollbar we extended the ScrollbarBase class with no actuall reason! maybe it was just an excitement to extend something! HeHeHe

But in this new version which I can call it the final version of a scrollbar, I didn't extend it BUT I did the class in a way that it can be easilly extended later. I thought of some future functionaleties that we may need in our software and it will be nicely possible to extend this current scrollbar and add or modify functionaleties to it, so this version can really be called the final version, I'm quite sure that I would  never again go to the trouble of creating a new Scrollbar class :)

I have also learned a couple of new things which I'm going to share with you.

The first thing that I really liked is the getter and setter functions, so with the help of them, I don't have to pass parameters within the class instance anymore and instead, I set them using the setter function. And another advantage of the setter function is that you are actually using them as private and the setter function will actually write them.

This way will also enable you not to start any action in the constructor function (unless you really need to) with which I mean, you will start the class by calling the "new ..." and set the variables, etc, etc and then after you are ready to use the class, you can manually call a function from outside and it will run the script.

Below you can see how the new class will except the variables. This way it looks much better, don't you think so?


		  
		  
		  
		  
		  
		  
		

Now let's have a look at how you use the getter and setter functions:
Ok, the first step is to know that you are using the getter and setter functions for a better encapsulation which enables you to set the variables in your class in private. It's better to set these variables in private because you surely do NOT want other extended classes to modify them, right? you only want them to be modified with the setter function. So, in our example we have the three variables set in the class like this.

 private var _width:Number = 0;
private var _height:Number = 0;
private var _position:String = "V";

and then you set the functions, in public. take below as an example of a setter function

public function set width(newWidth:Number):void
{
_width = newWidth;
}

take note of the public access method and the keyword "set". that's it! So, as the setter function is public you can easilly access it from outside as in our example like this.

myScroll.width = myScroll_mc.bg.width;

The getter function is also very similar to the setter and it will be used from the outside to read the current value of that property.

public function get width():Number
{
return _width;
}

Take note that getter functions must always have a return value and you will simply call them from the outside like this:

trace(myScroll.width);

And that's all there is to it about the setter and getter :)

 

Here you may download the final class for our scrollbar. (Saved in CS4)

And here is how it works. As you see, it works just like the last version, but this one is really orgenized! At least I think so right now!!! :) if you are coming up with a better version, please feel free to let me know.

And here is the whole code class for your reference.


		  
		  
		  
		  
		  
		  
		

Oh, and I almost forgot, I also found something very interesting on how you can handle something like onDragOver, onDragOut, and onReleaseOutside in ActionScript 3.0 (AS3)! As you know already, these events are no more explicitly available in AS3 but it surely does not mean that you can't use them!

I found an interesting article here which really helped me get my code a lot cleaner by using these nice mouse event properties like buttonDown, target and currentTarget!

Now, I'm going to create a drop down menu which is going to be used in our applet later. remember that it must be open for later extensions as we are going to use them in several diffrent ways... let's see what we can come up with in our drop down menu, keep reading my posts.

Regards,
Hadi

Tags: , , , , , , , , ,

9 Responses to “Final Scrollbar class V 2.0”

  1. Matej says:

    Hi Hadi, your scrollbar looks realy delicious. I would like to implement it in one of my projects if you are not against. I can give you some credit in html code. Would you be up to saving your fla to CS3 so I can examine it closer? I don’t want to see any other scrollbar anymore ;-)
    Thanks!!!

  2. admin says:

    Hi Matej, I’m happy to see you have liked the idea. yeah, you can use that scrollbar in your projects as the whole idea of creating this blog is to help other coders because I have found some websites that have helped me and then I decided to also help others!!! maybe we can make a better world :)

    well, right now I am not in a position to go through old files and convert them to older versions because just today I managed to setup my new comoputer (That’s probably you waited so long to hear back from me! I appolegize for that) but you can use the scripts on the pages to duplicate the very same thing. right? Good luck and keep checking back, my drop down meny class will be ready tomorrow I hope :)

  3. AS3 itemList Class V 1.0 « My Flash Lab! says:

    [...] my scrollbar class here I have made it in a way that enables you to drop any movieclip under the scrollbar so why don’t [...]

  4. Michael Neil says:

    I keep searching for a descent scrollbar class and this one seems like the best. Maybe that’s because I can’t open it! I searched your site everywhere hoping you had a cs3 version but you DON’T! Now I’m going to have to spend hours trying to figure out what the clip names are and how the thing functions. Might as well build my own… Anyway. If you’d save this as a cs3 version I’ll add a blur filter to snaz it up and give it back! C’mon, help me help you. It looks great but I wouldn’t know

  5. Hadi Tavakoli says:

    Hi michael, Happy to see you are finding this helpful. download the CS3 version from here.
    http://emstris.com/sample/AS3/Scrollbar/CS3_ScrollbarClassV2.0.zip
    I’d be happy to see it more enhanced!

  6. deamothul says:

    You really rule mate, i love your style of writing. Keep it up, love your work :D

  7. wow power leveling says:

    Looks like your question thing at the end of the post worked. Also not having to sign in is nice too. Good job. Nice list. Thanks.

  8. wow power leveling says:

    Wow, this is very useful.. Thanks for sharing this and hoping I could implement it too.

  9. metin2yang says:

    thanks share your artic!

Leave a Reply