I’m pretty new to actionscript so I’ve been following a couple of tutorials on making a custom video player and they all use the onMetaData event of the NetStream class to get the duration of the video. I always get this error though
ns.onMetaData = function(obj:Object){
1119: Access of possibly undefined property onMetaData through a reference with static type flash.net:NetStream.
Here’s what I have, sorry about the commented stuff I’ve been trying different things:
import flash.media.Video;
import flash.net.NetStream;
import flash.net.NetConnection;
import flash.events.*;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
//var metaObj:Object = new Object();
//ns.client = metaObj;
//metaObj.onMetaData = onMetaData;
pause_btn.visible= false;
var isPaused:Boolean = true;
var videoInterval = setInterval(videoStatus, 100);
var amountLoaded :Number;
var duration:Number;
/*metaObj.onMetaData = function(obj:Object)
{
duration = obj.duration;
}
/*function onMetaData(info:Object):void
{
duration = obj.duration;
}*/
//var theVideo:Video = new Video();
theVideo.attachNetStream(ns);
//ns.play("http://www.oumedicine.com/mpeg/infectiousdiseases.flv");
ns.onMetaData = function(obj:Object){
duration = obj.duration;
};
ns.play("http://gallery.rphmedia.net/albums/userpics/10001/jacko.flv");
ns.pause();
function playVideo(event:MouseEvent):void
{
if(isPaused)
{
pause_btn.visible=true;
play_btn.visible=false;
ns.resume();
}
else
{
ns.play("http://www.oumedicine.com/mpeg/infectiousdiseases.flv");
}
isPaused = false;
}
function pauseVideo(event:MouseEvent):void
{
play_btn.visible=true;
pause_btn.visible=false;
ns.pause();
isPaused = true;
}
function videoStatus()
{
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
loader.loadbar._width = amountLoaded * 572.6;
loader.scrub._x = ns.time / duration * 572.6;
}
play_btn.addEventListener(MouseEvent.CLICK, playVideo);
pause_btn.addEventListener(MouseEvent.CLICK, pauseVideo);