15 Replies Latest reply on Mar 18, 2012 4:48 PM by kglad

    Switching between FLVPlayback component at their playheadTime

    ViperCS5

      Hi There,

       

      I hope someone can save me with this.

      I am currently on a project (AS3), where I have 2 frames, with videos (using the FLVPlayback component).

      and I want to switch from one video to the next video, however the catch is when i switch to the next video I want the new video to play at the previous video time.

       

      example:

      Video 1 plays,  10 sec later, you click a button to go and see the next video (in another frame) and that new Video starts 10 sec into it.

       

      This is the codes I been using so far:

       

      ------------------------------

       

      import fl.video.VideoEvent;

      import fl.video.MetadataEvent;

       

       

      video1.addEventListener(VideoEvent.PLAYHEAD_UPDATE, timer);

       

       

      function timer(e:VideoEvent):void {

          var newTime = video1.playheadTime;

        

      };

       

       

      nextFrame_btn.addEventListener( MouseEvent.MOUSE_UP, nextFrame);

           

      function nextFrame (MouseEvent):void

      {

                                      

                  gotoAndStop(2);

            video2.playheadTime = newTime;

                 

                           

      }

       

      --------------------

       

      This doesn't work and I do not know what I am doing wrong.

       

      many thanks if you can help.

        • 1. Re: Switching between FLVPlayback component at their playheadTime
          kglad Adobe Community Professional & MVP

          use:

           

          var newTime:int;

          nextFrame_btn.addEventListener( MouseEvent.MOUSE_UP, nextFrame);

               

          function nextFrame (MouseEvent):void

          {

                                   

             newTime = video1.playheadTime;      

          this.addEventListener(Event.RENDER,renderF);

          stage.invalidate();

                      gotoAndStop(2);                 

          }

          function renderF(e:Event):void{

            video2.seek(newTime);

          }

          • 2. Re: Switching between FLVPlayback component at their playheadTime
            ViperCS5 Level 1

            I tried that and I get this info..

             

            TypeError: Error #1009: Cannot access a property or method of a null object reference.

                      at iybrid_fla::MainTimeline/switch1()

             

            NOTE: switch1 is my button name.

            • 3. Re: Switching between FLVPlayback component at their playheadTime
              kglad Adobe Community Professional & MVP

              that's a function name, not an object.

               

              click file>publish settings>flash and tick "Permit debugging".  retest.  the problematic frame/layer/line number will be in the error mesage. 

               

              copy and paste that line of code.

              • 4. Re: Switching between FLVPlayback component at their playheadTime
                ViperCS5 Level 1

                TypeError: Error #1009: Cannot access a property or method of a null object reference.

                          at iybrid_fla::MainTimeline/switch1()[iybrid_fla.MainTimeline::frame10:15]

                 

                is that it?

                • 5. Re: Switching between FLVPlayback component at their playheadTime
                  kglad Adobe Community Professional & MVP

                  yes, that's the error message.

                   

                  now, what's frame 10, line 15?

                  • 7. Re: Switching between FLVPlayback component at their playheadTime
                    kglad Adobe Community Professional & MVP

                    where's that code located?  if it's on a timeline, stage.invalidate() can't be causing the error.  to confirm, test using:

                     

                    var newTime:int;

                    nextFrame_btn.addEventListener( MouseEvent.MOUSE_UP, nextFrame);

                         

                    function nextFrame (MouseEvent):void

                    {

                                             

                       newTime = video1.playheadTime;      

                    this.addEventListener(Event.RENDER,renderF);

                    trace("stage:",stage);

                    stage.invalidate();

                                gotoAndStop(2);                 

                    }

                    function renderF(e:Event):void{

                      video2.seek(newTime);

                    }

                    • 8. Re: Switching between FLVPlayback component at their playheadTime
                      ViperCS5 Level 1

                      I just get that error again. 

                       

                      I am not sure what you mean by the code being on the timeline. The code is on new layer (in frame 10).

                      layer structure.

                                                              frame1               frame2          ....        frame10

                      action layer (AS3)                                                                       the coding(from here)

                      Video (videos)                                             video1          ....         video2

                      Buttons (the buttons)      ------------------   B    u    t    t   o   n    s  ---------------

                       

                       

                      TypeError: Error #1009: Cannot access a property or method of a null object reference.

                                at iybrid_fla::MainTimeline/d3switch1()[iybrid_fla.MainTimeline::frame10:15]

                      • 9. Re: Switching between FLVPlayback component at their playheadTime
                        kglad Adobe Community Professional & MVP

                        you're misreporting something.

                         

                        if the error were stage.invalidate(), then that trace() output would occur prior to the error message.  in addition, the error message would reference line 16 because stage.invalidate() is no longer on line 15 after you add that trace.  and there are other inconsistencies.

                         

                        anywya, do you have more than 1 layer with code in frame 10?  if not, copy the first 20 lines or so in frame 10, paste them here and bold line 15.

                        • 10. Re: Switching between FLVPlayback component at their playheadTime
                          ViperCS5 Level 1

                          yes there is another layer with codes but that is for the buttons.. that can work throughout the flash (in all frames). Sorry I forgot about that. Those buttons are just basic home, end buttons. In the other layer is the switch code for the button I am trying to make.

                           

                          This button/code for some reason does not like being in the main code layer. So I added it in another layer, which seem to make it work. (The part where I want it to gotoAndStop in another frame.)

                           

                          ----------

                           

                          var newTime:int;

                          switch_btn.addEventListener(MouseEvent.MOUSE_UP, switch1);

                               

                          function switch1 (MouseEvent):void // Function to turn on 3D mode

                          {

                                              newTime = video1.playheadTime;     

                                              this.addEventListener(Event.RENDER,renderF);

                          trace("stage:",stage);

                                              stage.invalidate();     <= that use to be line 15 before the trace was added.

                                  gotoAndStop(2);  

                                              trace (newTime);

                          }

                          function renderF(e:Event):void{

                            video1.seek(newTime);

                          }

                           

                          --------

                           

                          the other layer has this code:

                           

                          cha1_btn.addEventListener(MouseEvent.MOUSE_UP, cha1);

                          chan2_btn.addEventListener(MouseEvent.MOUSE_UP, chan2);

                           

                          function cha1 (MouseEvent):void

                          {

                                    gotoAndStop(10);

                           

                          }

                           

                           

                          function chan2 (MouseEvent):void

                                    gotoAndStop(11);

                          }

                           

                          -----

                           

                          They are on seperate layers because the switch function is used in all the frames, but to gotoAndStop in different frames.

                           

                          aka this one: is in frame 10, which goes to frame 2

                          and there will be another one in frame 2 to go to frame 10.

                           

                          then there is another in frame 11, which goes to frame 3

                          and then the same for frame 3 to goto frame 11.

                           

                          so thats why there were in seperate layers, to be able to change that. (sorry if this is getting confusing)

                          • 11. Re: Switching between FLVPlayback component at their playheadTime
                            kglad Adobe Community Professional & MVP

                            layers don't even exist in your published swf so your code is not segregated by layer in the published swf.

                             

                            so, how many keyframes (in different layers) contain code at frame 15?

                            • 12. Re: Switching between FLVPlayback component at their playheadTime
                              ViperCS5 Level 1

                              1 key frame in frame 10...

                              but I guess it reading 2 layers of code.

                              • 13. Re: Switching between FLVPlayback component at their playheadTime
                                kglad Adobe Community Professional & MVP

                                if there's only one keyframe, what's the trace an error panel output using:

                                 

                                var newTime:int;

                                switch_btn.addEventListener(MouseEvent.MOUSE_UP, switch1);

                                     

                                function switch1 (MouseEvent):void // Function to turn on 3D mode

                                {

                                                    newTime = video1.playheadTime;     

                                                    this.addEventListener(Event.RENDER,renderF);

                                trace("stage:",stage);

                                                    stage.invalidate();    // <= that use to be line 15 before the trace was added.

                                        gotoAndStop(2);  

                                                    trace (newTime);

                                }

                                function renderF(e:Event):void{

                                  video1.seek(newTime);

                                }

                                1 person found this helpful
                                • 14. Re: Switching between FLVPlayback component at their playheadTime
                                  ViperCS5 Level 1

                                  I manage to get it working.. Thank you!

                                   

                                  however I have a little new issue.

                                   

                                  I need the videos to stop playing when they enter a new frame.

                                   

                                  I used video1.stop()

                                   

                                  which works nicely, but for some reason the codes for the switch button is over writting it and allowing it to continue to play (sound wise).

                                   

                                  code:

                                   

                                  if (video1 != null){

                                            video1.stop();

                                            }

                                   

                                  it works nice. But when using this coding:

                                   

                                  video2.stop();

                                  gotoAndStop(10);

                                        video1.playheadTime = nTime;

                                   

                                   

                                  it still plays in the background. (sound wise)

                                  • 15. Re: Switching between FLVPlayback component at their playheadTime
                                    kglad Adobe Community Professional & MVP

                                    what was the problem?

                                     

                                    and, what video (video1 or video2) is playing in the bg?