[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

AS3 Scrubber bar problem

Posted on 2008-11-11
1
Medium Priority
?
979 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:jordanaustin
1 Comment
 
LVL 2

Accepted Solution

by:
jordanaustin earned 0 total points
ID: 22935063
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question