2 Replies Latest reply on Apr 15, 2009 4:25 PM by VideoE

    Creating Preloader in AS3

    VideoE Level 1

      I'm trying to figure out how to create a preloader for a progressively loaded video in Actionscript 3.  Preferably without using the flv playback component.  I know a bit about the  NetStream object and I've followed both the older Brimelow video tutorial set and the AS3 update one.  But Lee and everyone else seem to stop short of explaining the code for a preloader, either bar or % text.  I know it's still a bytesLoaded/bytes/Total thing but I'm not sure what kind of event listener to use, what parameter of the net stream object to access, etc.

       

      So if someone show me the code for a preloader, I would really appreciate it.

        • 1. Re: Creating Preloader in AS3
          kglad Adobe Community Professional & MVP

          the netstream class has bytesLoaded and bytesTotal properties.

          • 2. Re: Creating Preloader in AS3
            VideoE Level 1

            kglad, thanks for the response.  Yes, I understand the byteLoaded/bytesTotal thing, as I explained in the original post.  It's getting that info from the NetStream I'm having a problem with currently.  Also, I want to dump the preloader, ( think), after the video is loaded.  This is what I have , minus the code to handle the metadata.  Both the video and the loader show up, but I'm not sure how to connect the loadbar code with the NetStream info that will get it to work.  (Hopefully.)

             

             

             

            var video:Video = new Video();
            addChild(video);
            addChild(loader_mc);

             

            var nc:NetConnection = new NetConnection();
            nc.connect(null);
            var ns:NetStream = new NetStream(nc);
            video.attachNetStream(ns);
            ns.play("E&E_Intro_New2.flv");

             

             

            var _amountLoaded:Number = (ns.bytesLoaded / ns.bytesTotal) * 100;
                 loader_mc.loadbar.width = _amountLoaded * 2.07;
                 if (_amountLoaded >= 207)
                 removeChild(loader_mc);