AS3: Video Question

Hello everyone,

I’m working on a video class and it’s driving me nuts. I’m taking the elements used in as2 and going to as3 but for some reason i keep hitting a wall. Here is my first class code:


package {

    import flash.display.Sprite;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import flash.media.Video;
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.events.NetStatusEvent;
    import flash.utils.Timer;

    public class myVideoClass extends Sprite {

        private var _video:Video;
        private var _stream:NetStream;
        private var _timer:Timer;

        public function myVideoClass () {

            _timer=new Timer(1000);
            _timer.addEventListener(TimerEvent.TIMER,onTimer);
            _timer.start();
        }
        public function playFlv(flvUrl) {
            _video=new Video(480,360);

            var connection:NetConnection=new NetConnection;
            connection.connect(null);

            _stream=new NetStream(connection);
            _stream.play(flvUrl);

            var Client:Object=new Object;
            Client.onMetaData=onMetaData;
            
            _stream.client=Client;
            _video.attachNetStream(_stream);

            _stream.addEventListener(NetStatusEvent.NET_STATUS,onNetStatus);
            addChild(_video);


        }
        private function onMetaData(data:Object) {

            var durMinutes:int = Client.duration;
            var durSeconds:int = Client.duration -60* durMinutes;
            var durMins:String = durMinutes.toString();
            var durSecs:String = durSeconds.toString();
            if (durMinutes<10) {
                durMins = "0" + durSecs;

            }
            if (durSeconds<0) {
                durSecs = "0" + ":" + durSecs;
            }

            time.text =  durMins + ":" + durSecs;

        }
        private function onNetStatus(e:NetStatusEvent) {

            _video.x = 94;
            _video.y = 303;

        }
        public function onTimer(t:TimerEvent) {

            var minutes:int = _stream.time/60;
            var seconds:int = _stream.time-60 * minutes;
            var minString:String = minutes.toString();
            var secString:String = seconds.toString();

            if (minutes<10) {

                minString = "0" + minString;
            }
            if (seconds<10) {
                secString = "0" + secString;
            }
            dur.text = minString + ":" + secString;

        }
    }
}

Here is my second file that launches the movie.


package myVideoClass{
    import flash.display.Sprite;

    public class Main extends Sprite {
        public function Main() {
            var v:Sprite=new myVideoClass();
            v.playFlv("myclip.flv");
            addChild(v);

        }
    }
}

When i run it i get the following error:
“1061: Call to a possibly undefined method playFlv through a reference with static type flash.display:Sprite.”

Any suggestions? Thanks!

You probably want to move the starting of your timer after you know you have a video stream to access information from. Otherwise, its going to throw errors.

Why are you using the netstatus event to position your video? Positioning it can be done in your class constructor, or in your playFlv method.