We are almost done with our Scrollbar class. slider and up and down buttons and mouse wheel all working fine now. check below. (Note that you must first click on the flash object to get the focus to the flash object.)
And you can download the files from here.
Although we are having all we need with this scrollbar now but it still needs to be tuned a bit more. I don't like how the codes are orgenized. in the next version I try to use some more rules from AS3 to make a clean and better code.
For now, let's see how we have managed the action on the up and down buttons. It's clear that we would need a MOUSE_DOWN listener to find out when the button is pressed so we use the follwoing on the cunstrctor function
_up.addEventListener(MouseEvent.MOUSE_DOWN, down);
this event will call a function called "down" and in that function we have:
There are some helpful notes to know about the Mouse events and that's the point that when a function is called via any mouse events, a parameter is also passed to the function automatically which holds a couple of values and one of these values is the target which is actually the movieclip which the event listener has been registered to.
If you are wondering what other MOUSE events are available in AS3, Here is a list of all the mouse events in AS3:
CLICK : String = “click” MouseEvent
Used to detect mouse clicks.
DOUBLE_CLICK : String = “doubleClick” MouseEvent
Used to detect double clicks.
MOUSE_DOWN : String = “mouseDown” MouseEvent
Checks when mouse is pressed down.
MOUSE_LEAVE : String = “mouseLeave” Event
Monitors when the mouse leaves the stage.
MOUSE_MOVE : String = “mouseMove”
Monitors when the mouse moves.
MOUSE_OUT : String = “mouseOut”
Monitors when the mouse moves out of the object that the event has been attached to.
MOUSE_OVER : String = “mouseOver”
Monitors when the mouse moves over the object that the event has been attached to.
MOUSE_UP : String = “mouseUp”
Monitors when the mouse moves up the attached to object of the event from a click.
MOUSE_WHEEL : String = “mouseWheel”
Monitors when the mouse wheel moves, detect the positive or negative delta property for distance and direction moved.
There's nothing you can't do with your mouse the help of these mouse events. I like this much more than how they where in AS2!
ok, back to our script, when the mouse is down and the event.target detects that the object is the up button, it will start the timer class and the timer class will call "timerHandlerUp" every 10 milliseconds. the same thing happens if the _do buttons is clicked but this time the "timerHandlerDo" function will be called. It's clear that we must remove the timer listener as soon as the mouse is up.
You know what, there are a lot of parts in AS3 that surely makes our job easier but still there are some of them who are hard to be understood and one of them is the Timer class! Although I have been able to use it successfully, but I'm not clear about some of its features. in some other topics I will try to get very detailed on this Timer class and see how it works exactly.
Anyway, below is the modified file for the Scrollbar class.
It really needs to get clean! I'll take acre of that in my next post.
Regards,
Hadi

My Flash Lab