Restricting our dragging: Vertical only!

Restricting the dragging, and confining it to only the y direction is easy: Just forget what I told you about that xOffset number and get rid of it. Here's the code with all the lines that referenced the xOffset deleted:

import flash.events.MouseEvent;

var yOffset:Number;

thumb.buttonMode = true;
thumb.addEventListener(MouseEvent.MOUSE_DOWN, thumb_onMouseDown);
function thumb_onMouseDown(event:MouseEvent):void {
	yOffset = mouseY - thumb.y;
	stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_onMouseMove);
	stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
}

function stage_onMouseMove(event:MouseEvent):void {
	thumb.y = mouseY - yOffset;
	event.updateAfterEvent();
}

function stage_onMouseUp(event:MouseEvent):void {
	stage.removeEventListener(MouseEvent.MOUSE_MOVE, stage_onMouseMove);
	stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
}

And here's how the swf behaves with those code changes:

Now you can only drag up and down! Next we will proceed to add a "track" movie clip. That happens on the next page. This page was a really short one, wasn't it? Don't get too used to it.