5 Replies Latest reply: Aug 1, 2011 3:18 PM by kglad RSS

    preloader for dynamically added video

    I Love Doing Websites Community Member

      Hello,

      can you show me how to do a preloader for a dynamically added video? I used this code:

       

      I also have a bit of code to stop the video from playing and then resuming again.

       

      import flash.net.NetConnection;
      import flash.net.NetStream;
      import flash.events.AsyncErrorEvent;
      import flash.events.NetStatusEvent;
      import flash.utils.Timer;

       

      /*
      1)convert the video into an flv or f4v supported format
      2) go to library and select new video
      3)place the video to the stage
      4)give an instance name of videoHolder
      */
      var myVideo:NetConnection = new NetConnection ();
      //null because we are going to use the video from the server or from the computer, we are not using the adobe video stream services
      myVideo.connect(null);
      var newStream:NetStream = new NetStream(myVideo);
      //a new NetStream object is instatiated
      //enter the attachNetStream() method with the video source parameter
      videoHolder.attachNetStream(newStream);
      //enter the name of teh NetStream object followed by a period and then the method play. as the parameter for the play method enter the name of the external FLV or F4V file that you want to play on the stage
      newStream.play("../flash/video/104339598_q.flv");
      var counter:Number = 0;
      trace (counter);

       

      //test the movie
      //we are going to get rid of the asynchronous errors here
      newStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
      function asyncErrorHandler(myevent:AsyncErrorEvent):void{
          //ignore error
      }
      newStream.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
      function statusHandler(myevent:NetStatusEvent):void{
          if(myevent.info.code =="NetStream.Play.Stop"){
             
              var myTimer:Timer=new Timer(10500, 2);
      myTimer.start();
      myTimer.addEventListener(TimerEvent.TIMER, playVideoAgain);

       

      function playVideoAgain(myEvent:TimerEvent):void{
          counter++;
          if (counter <4){
          playAgain();
          }
          else{newStream.pause();}
         
      }
              function playAgain(){
                  newStream.seek(0);
                  newStream.play("../flash/video/104339598_q.flv");
                  myTimer.stop();
                 
                  trace(counter);
              }
          }
         
         
      }