Hello I am making an OOP scroll bar. I have three classes
- ScrollBox
This class contains the scroll bar and a container that hold the images to be scrolled.
- Scroll Bar
This class controls the scrolling of the bar and dispatches a scrollbar event containing the percentage to which the thumb bar is moved.
- ScrollBarEvent class.
This class simply fires an event with the event object containing the percentage of the scroll bar scrolling.
Now Everything was running fine when it was on the stage but as I moved the code in classes it give a TYPE ERROR 1009 saying it cant access a property or method of null object reference.
The error comes when I create an object of scroll bar inside the scroll box class. I am pasting the code for the classes below.
SCROLL BAR Class
package
{
import flash.display.*;
import flash.events.*;
public class ScrollBar extends MovieClip
{
private var xOffset:Number;
private var xMin:Number;
private var xMax:Number;
public function ScrollBar():void
{
xMin = 0;
xMax = track.width - thumb.width;
thumb.addEventListener(MouseEvent.MOUSE_DOWN, thumbDown);
track.addEventListener(MouseEvent.MOUSE_DOWN, trackDown);
stage.addEventListener(MouseEvent.MOUSE_UP, thumbUp);
}
public function trackDown(e:MouseEvent):void
{
//stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
//yOffset = mouseY - thumb.y;
thumb.x = mouseX ;
if (thumb.x <= xMin)
{
thumb.x = xMin;
}
if (thumb.x >= xMax)
{
thumb.x = xMax;
}
dispatchEvent (new ScrollBarEvent(thumb.x / xMax));
}
private function thumbDown(e:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
xOffset = mouseX - thumb.x;
}
private function thumbUp(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
}
private function thumbMove(e:MouseEvent):void
{
thumb.x = mouseX - xOffset;
if (thumb.x <= xMin)
{
thumb.x = xMin;
}
if (thumb.x >= xMax)
{
thumb.x = xMax;
}
dispatchEvent (new ScrollBarEvent(thumb.x / xMax));
e.updateAfterEvent();
}
}//end of class
}// End of package
ScrollBox Class
package
{
import flash.display.*;
import flash.events.*;
import caurina.transitions.*;
public class ScrollBox extends MovieClip
{
private var scrollBar:ScrollBar;
private var masker:Masker;
private var content:Content;
public function ScrollBox():void
{
scrollBar = new ScrollBar();
scrollBar.x = 100;
scrollBar.y = 50;
addChild(scrollBar);
scrollBar.addEventListener(ScrollBarEvent.VALUE_CHANGED, sbChange);
}
public function sbChange(e:ScrollBarEvent):void
{
Tweener.addTween(content, {x:(-e.scrollPercent*(content.width - masker.width)), time:1});
}
}//end of class
}// End of package
Scroll bar movie clip is in the library and contains two movieclips one with instance name thumb and another one with name track.
Can anyone please help I have really given up on this now Thanks in advance