AS3 Scrubber bar problem

Hello, I am new to AS3 and I am a bit confused. I am creating a custom scrubber bar for my .flv. It is working, but its not working very well. When I drag the scrubber across the track it works ok but it flickers, then when I release it then it jumps to a different places and will not seek very precisely.

Thanks for any help
var video:Video = new Video(465.348);
video_mc.addChild(video);
 
var nc:NetConnection = new NetConnection();
nc.connect(null);
 
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent);
 
function onStatusEvent(stat:Object):void
{
	trace(stat.info.code);
}
var metaListener:Object = new Object();
metaListener.onMetaData = theMeta;
ns.client = metaListener;
video.attachNetStream(ns);
 
ns.play("theVideo.flv");
scrubber.scrubHandle.buttonMode = true;
stage.addEventListener(Event.ENTER_FRAME, enterFrame);
scrubber.scrubHandle.addEventListener(MouseEvent.MOUSE_DOWN, scrubDown);
scrubber.scrubHandle.addEventListener(MouseEvent.MOUSE_UP, scrubTo);
 
var xOffset:Number;
var xMin:Number = 0;
var xMax:Number = 430;
var totalLength:uint;
 
function theMeta(data:Object):void
{
	totalLength = data.duration;
}
 
 
function enterFrame(e:Event):void
	{
	var currentSecs:Number = Math.floor(ns.time);	
	var totalSecs:Number = Math.round(totalLength);
	if(currentSecs > 0)
	{
	var amountPlayed:Number = ns.time / totalLength;
	var amountLoaded:Number = ns.bytesLoaded / ns.bytesTotal;
	scrubber.track.width = amountLoaded * 430;
	scrubber.scrubHandle.x = ns.time / totalLength * 430;
 }
}
 
function scrubDown(e:MouseEvent):void
{
	stage.addEventListener(MouseEvent.MOUSE_MOVE, scrubFollow);
	xOffset = mouseX - scrubber.scrubHandle.x;
}
 
function scrubFollow(e:MouseEvent):void
{
	scrubber.scrubHandle.x = mouseX - xOffset
	if(scrubber.scrubHandle.x <= xMin)
	scrubber.scrubHandle.x = xMin;
	if(scrubber.scrubHandle.x >= xMax)
	scrubber.scrubHandle.x = xMax;
	e.updateAfterEvent();
	}
	
function scrubTo(e:MouseEvent):void
{
	stage.removeEventListener(MouseEvent.MOUSE_MOVE, scrubFollow);
	stage.removeEventListener(MouseEvent.MOUSE_MOVE, scrubDown);
if(scrubber.scrubHandle.mouseX < scrubber.track.width)
var percentAcross:Number = (scrubber.scrubHandle.x) / scrubber.track.width;
	ns.seek(totalLength * percentAcross);
 
e.updateAfterEvent();
}

Open in new window

LVL 2
jordanaustinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jordanaustinAuthor Commented:
Ok, I solved it myself. In case anyone else is wondering I've posted the code below. Also if anyone see's a better way to do this please let me know. Thanks!
var video:Video = new Video(465.348);
video_mc.addChild(video);
 
var nc:NetConnection = new NetConnection();
nc.connect(null);
 
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent);
 
function onStatusEvent(stat:Object):void
{
	trace(stat.info.code);
}
var metaListener:Object = new Object();
metaListener.onMetaData = theMeta;
ns.client = metaListener;
video.attachNetStream(ns);
 
ns.play("theVideo.flv");
scrubber.scrubHandle.buttonMode = true;
stage.addEventListener(Event.ENTER_FRAME, enterFrame);
scrubber.scrubHandle.addEventListener(MouseEvent.MOUSE_DOWN, scrubDown);
scrubber.scrubHandle.addEventListener(MouseEvent.MOUSE_UP, scrubTo);
 
var xOffset:Number;
var xMin:Number = 0;
var xMax:Number = 430;
var totalLength:uint;
 
function theMeta(data:Object):void
{
	totalLength = data.duration;
}
 
 
function enterFrame(e:Event):void
	{
	var currentSecs:Number = Math.floor(ns.time);	
	var totalSecs:Number = Math.round(totalLength);
	if(currentSecs > 0)
	{
	var amountPlayed:Number = ns.time / totalLength;
	var amountLoaded:Number = ns.bytesLoaded / ns.bytesTotal;
	scrubber.track.width = amountLoaded * 430;
	scrubber.scrubHandle.x = ns.time / totalLength * 430;
 }
}
 
function scrubDown(e:MouseEvent):void
{
	stage.addEventListener(MouseEvent.MOUSE_MOVE, scrubFollow);
	stage.removeEventListener(Event.ENTER_FRAME, enterFrame);
	xOffset = mouseX - scrubber.scrubHandle.x;
}
 
function scrubFollow(e:MouseEvent):void
{
	scrubber.scrubHandle.x = mouseX - xOffset
	if(scrubber.scrubHandle.x <= xMin)
	scrubber.scrubHandle.x = xMin;
	if(scrubber.scrubHandle.x >= xMax)
	scrubber.scrubHandle.x = xMax;
	e.updateAfterEvent();
	}
	
function scrubTo(e:MouseEvent):void
{
	stage.removeEventListener(MouseEvent.MOUSE_MOVE, scrubFollow);
	var percentAcross:Number = (scrubber.scrubHandle.x) / scrubber.track.width;
	ns.seek(totalLength * percentAcross);
	stage.removeEventListener(MouseEvent.MOUSE_MOVE, scrubDown);
		stage.addEventListener(Event.ENTER_FRAME, enterFrame);
 
 e.updateAfterEvent();
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.