9 Replies Latest reply on Aug 18, 2010 11:31 AM by kglad

    Rookie Question

    mathphile

      Hi there,

       

      I am designing a slideshow comprised of photos, video and some animations. I decided to use Flash because I thought it would offer me more flexibility than other options and because I have some experience coding in ActionScript 2.0 (though oddly very little experience designing swf's).

       

      Here's the thing. In frame 1 I want a video to play. I can make that happen using this code, copied straight from the help:

       

      stop();
      var nDuration:Number = 0;
      var my_video:Video;
      var my_nc:NetConnection = new NetConnection();
      my_nc.connect(null);
      var my_ns:NetStream = new NetStream(my_nc);
      my_video.attachVideo(my_ns);
      my_ns.play("FLVPlayback");

       

      This works great but f course the movie is no longer playing, so nothing happens when the video ends. Now if I add the play() command at the end, I get the rest of the movie but the video never seems to play.

       

      This must be very simple, but I can't figure it out and I've spent the last 4 hours trying to. How can I tell when the video has stopped so that I can issue the play() command?

       

      I tried looping on the my_ns status waiting for time to equal duration, but the onStatus only fired once when the video started.

       

      Thanks very much for your help.

        • 1. Re: Rookie Question
          kglad Adobe Community Professional & MVP

          use:

           


           

          stop();
          var nDuration:Number = 0;
          var my_video:Video;
          var my_nc:NetConnection = new NetConnection();
          my_nc.connect(null);
          var my_ns:NetStream = new NetStream(my_nc);
          my_video.attachVideo(my_ns);

          my_ns.onMetaData = function(evt:Object):Void {

            nDuration = evt.duration;

          };

          my_ns.onStatus = function(evt:Object):Void {

            if (this.time > 0 && this.time >= duration) {

            play()

           

              delete this.onStatus;

            }

          }

           

          my_ns.play("FLVPlayback");

          1 person found this helpful
          • 2. Re: Rookie Question
            mathphile Level 1

            Thank you. That is exactly what I tried (the exact code, as a matter of fact,

            which I copied from a different thread where you are also helping), but the

            onStatus is only firing once at the beginning of the video (which I could tell

            be adding a trace on the timer);

            • 3. Re: Rookie Question
              kglad Adobe Community Professional & MVP

              then use:

               


               


               

              stop();
              var nDuration:Number = 0;
              var my_video:Video;
              var my_nc:NetConnection = new NetConnection();
              my_nc.connect(null);
              var my_ns:NetStream = new NetStream(my_nc);
              my_video.attachVideo(my_ns);

              my_ns.onMetaData = function(evt:Object):Void {

                nDuration = evt.duration;

              clearInterval(endVideoI);

              endVideoI=setInterval(endVideoF,500);

              };

              function endVideoF():Void {

                if (my_ns.time > 0 && my_ns.time >= nDuration) {

                play()

               


                }

              }

               

              my_ns.play("FLVPlayback");

              • 4. Re: Rookie Question
                mathphile Level 1

                Once more, thank you for your help.

                 

                I tried the code you provided, but that isn't working either for some reason. I

                put a trace in the onMetaData function and it never fired.

                • 5. Re: Rookie Question
                  kglad Adobe Community Professional & MVP

                  copy and paste the code you're using and the url to your html if you're testing online.

                  • 6. Re: Rookie Question
                    mathphile Level 1

                    Here it is. Note the trace, which is not firing at all. I am running the file

                    locally on my computer.

                     

                     

                    stop();

                    var nDuration:Number = 0;

                    var my_video:Video;

                    var my_nc:NetConnection = new NetConnection();

                    my_nc.connect(null);

                    var my_ns:NetStream = new NetStream(my_nc);

                     

                    my_ns.onMetaData = function(evt:Object):Void  {

                        nDuration = evt.duration;

                        trace(nDuration);

                        clearInterval(endVideoI);

                        endVideoI = setInterval(endVideoF, 500);

                    };

                     

                    my_video.attachVideo(my_ns);

                     

                    function endVideoF():Void {

                        if (my_ns.time>0 && my_ns.time>=nDuration) {

                            play();

                        }

                    }

                     

                    my_ns.play("FLVPlayback");

                    • 7. Re: Rookie Question
                      kglad Adobe Community Professional & MVP

                      what's

                       

                      my_ns.play("FLVPlayback");

                       

                      ???

                       

                      you're not playing an flv with that code.  you should be using something like

                       

                       

                      my_ns.play("yourflvname.flv");

                      • 8. Re: Rookie Question
                        mathphile Level 1

                        Thank you. That was code I copied directly from the Flash Help. What I did was

                        import the video using File->Import->Import Video ...

                         

                        Then I browsed for the .flv on my computer, and selected "Load external video

                        with playback component". What that did was add an item to my library called

                        FLVPlayback.

                         

                        Since the video played, I thought my code was doing it. After I read your post I

                        commented out the my_ns.play("FLVPlayback"), and of course the video still

                        plays, as I now think I understand what I did, and why I was confused. I have

                        removed the video from my library.

                         

                        Here's the code I am using now, which behaves as expected with the events firing

                        properly:

                         

                        stop();

                        var nDuration:Number = 0;

                        var my_video:Video;

                        var my_nc:NetConnection = new NetConnection();

                        my_nc.connect(null);

                        var my_ns:NetStream = new NetStream(my_nc);

                         

                        my_ns.onMetaData = function(evt:Object):Void  {

                            nDuration = evt.duration;

                            trace(nDuration);

                            clearInterval(endVideoI);

                            endVideoI = setInterval(endVideoF, 500);

                        };

                         

                        my_video.attachVideo(my_ns);

                         

                        function endVideoF():Void {

                            if (my_ns.time>0 && my_ns.time>=nDuration) {

                                play();

                            }

                        }

                         

                        my_ns.play("kiteflying.flv");

                         

                        Now the problem I am having is that I get audio but no video.

                        • 9. Re: Rookie Question
                          kglad Adobe Community Professional & MVP

                          start over and don't import your video.

                           

                          add video your library (click the upper right, new video) and then drag to your stage and in the properties panel type my_video to assign your video instance an instance name that matches your code.