Hi guys,
I am trying to create a slider component class using AS 3.0. The slider works ok, but there is the onReleaseOutside problem. After googling, i came to the conclusion that one would add the MOUSE_UP event to the a eventlistener attached to the stage, and all would be fine.
However, the following code would give me a type error 1009 which complains about a null object.
public function Slider(t:MovieClip, m:MovieClip){
track = t;
marker = m;
rectangle = new Rectangle(track.x, marker.y, track.width, 0); //Create the rectangle to bound the marker
marker.addEventListener(MouseEvent.MOUSE_DOWN, startSliding);
marker.buttonMode = true;
}
//Starts the sliding session
private function startSliding(event:MouseEvent):void
{
stage.addEventListener(MouseEvent.MOUSE_UP, stopSliding); //DOES NOT WORK
event.target.addEventListener(MouseEvent.MOUSE_MOVE, updateOutput);
event.target.startDrag(false, rectangle);
}
//Ends the sliding session
private function stopSliding(event:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, stopSliding); //SAME PROBLEM AS ABOVE
event.target.stopDrag();
event.target.removeEventListener(MouseEvent.MOUSE_MOVE, updateOutput);
}
private function updateOutput(event:MouseEvent):void
{
//do stuff
}
I have tried
Stage(event.Target).addEventListener(MouseEvent.MOUSE_UP, stopSliding)
which doesnt work either.
Any ideas appreciated
Cheers