12 Replies Latest reply on Mar 19, 2015 2:52 PM by JacquelineSebrey

    How to stop videos using Action Script?

    JacquelineSebrey Level 1

      I imported external videos to my Flash App and when I test my movie and I click on a button that takes me to the frame where a video is and I start the video and then go and click on another button that takes me to the main frame or "home" the video is still playing in the background. Is there a way to get the videos to automatically stop when you click on another button or go to "home" (Frame 1) or something? Just putting in stop(); does not stop the videos and my customer does not like the fact that you have to click on pause on the video player and then click on another button to go to another video. Any help and advice will be greatly appreciated!!!

        • 1. Re: How to stop videos using Action Script?
          kglad Adobe Community Professional & MVP

          if you video is being played in an flvplayback component, assign the component an instance name (in the properties panel, eg flv_pb) and in the actions panel add:

           

          flv_pb.addEventListener(Event.REMOVED_FROM_STAGE,f);

          function f(e:Event):void{

          flv_pb.stop();

          }

          • 2. Re: How to stop videos using Action Script?
            JacquelineSebrey Level 1

            Okay, so my next question is: How do you make a video as an flvplayback component? I just did file>Import>Import Video and it showed up on the stage and in the correct layer and in the correct frame. Then I labeled my frames and created Action Script for the buttons to go to whatever label is for that particular video's frame. I hope that I'm explaining this properly. I've done searches elsewhere and it seems that this is a common problem with videos in Flash. I just need to find out the proper way to import videos in such as using the flvplayback component (please either give me instructions on how to do this or send me a link that tells you). Thank you.

            • 3. Re: How to stop videos using Action Script?
              kglad Adobe Community Professional & MVP

              if you used the default settings it is being played in an flvplayback component.

              • 4. Re: How to stop videos using Action Script?
                JacquelineSebrey Level 1

                I so feel stupid for asking this but I have 4 videos on the same layer just in different frames. How do I know the default settings or flvplayback component for each video? The first video is in Frame 10 and the label for Frame 10 is "selma" and the second video is in Frame 20 and the label for Frame 20 is "tim" and the third video is in Frame 30 and the label for Frame 30 is "itvpt" and the fourth video is in Frame 40 and the label for Frame 40 is "itvcare". I created a buttons layer and in the first frame in the Actions Layer I coded:

                 

                stop();

                import flash.events.MouseEvent;

                 

                 

                home.addEventListener(MouseEvent.CLICK,homeBtn);

                selma.addEventListener(MouseEvent.CLICK,selmaBtn);

                tim.addEventListener(MouseEvent.CLICK,timBtn);

                itvpt.addEventListener(MouseEvent.CLICK,itvptBtn);

                itvcare.addEventListener(MouseEvent.CLICK,itvcareBtn);

                 

                 

                function homeBtn(event:MouseEvent){

                  gotoAndPlay("home");

                }

                 

                 

                function selmaBtn(event:MouseEvent){

                  gotoAndPlay("selma");

                }

                 

                 

                function timBtn(event:MouseEvent){

                  gotoAndPlay("tim");

                }

                 

                 

                function itvptBtn(event:MouseEvent){

                  gotoAndPlay("itvpt");

                }

                 

                 

                function itvcareBtn(event:MouseEvent){

                  gotoAndPlay("itvcare");

                }

                 

                So, you click on a button and it will take you to the frame with that label like "selma". I'm sorry but I just feel really dense right now and this is after having 3 classes in Flash in college and I have over a dozen books on Flash and Action Script 3.0. All I did for each video was go to the video layer I created and just imported the video and the additional problem is that these videos are not in .flv or .f4v format. They are in .mov formate using the H.264 codec as I couldn't find .f4v or .flv in Adobe Media Encoder. Could the .mov format be the problem and if it is what do I do to fix this as my customer/client is not happy right now. Right now my top priority is to get these videos to automatically stop when you click on a button to go to another video or text pages. If I can't get this to work I may not have a customer/client. That's how important it is that I figure this out and get it to work ASAP. Thank you for understanding and being patient with me.

                • 5. Re: How to stop videos using Action Script?
                  JacquelineSebrey Level 1

                  By the way, if I click on the video in the layer and frame on the right the Property does say instance of FLVPlayback and it is the same for each video when I click on them. Is this what you are talking about?

                  • 6. Re: How to stop videos using Action Script?
                    JacquelineSebrey Level 1

                    I thought I had it and I found when I clicked on the video on the Right at the top of properties it says SWF and underneath you could give it an instance name and I did that like your suggestion and below is my Action Script for Frame 1:

                    import flash.events.MouseEvent;

                    import flash.events.Event;

                     

                     

                    home.addEventListener(MouseEvent.CLICK,homeBtn);

                    selma.addEventListener(MouseEvent.CLICK,selmaBtn);

                    tim.addEventListener(MouseEvent.CLICK,timBtn);

                    itvpt.addEventListener(MouseEvent.CLICK,itvptBtn);

                    itvcare.addEventListener(MouseEvent.CLICK,itvcareBtn);

                     

                     

                    function homeBtn(event:MouseEvent){

                      gotoAndPlay("home");

                    }

                     

                     

                    function selmaBtn(event:MouseEvent){

                      gotoAndPlay("selma");

                    }

                     

                     

                    function timBtn(event:MouseEvent){

                      gotoAndPlay("tim");

                    }

                     

                     

                    function itvptBtn(event:MouseEvent){

                      gotoAndPlay("itvpt");

                    }

                     

                     

                    function itvcareBtn(event:MouseEvent){

                      gotoAndPlay("itvcare");

                    }

                     

                     

                    selma_pb.addEventListener(Event.REMOVED_FROM_STAGE,selma_f);

                    function selma_f(e:Event):void{

                    selma_pb.stop();

                    }

                     

                     

                    tim_pb.addEventListener(Event.REMOVED_FROM_STAGE,tim_f);

                    function tim_f(e:Event):void{

                      tim_pb.stop();

                    }

                     

                     

                    itvpt_pb.addEventListener(Event.REMOVED_FROM_STAGE,itvpt_f);

                    function itvpt_f(e:Event):void{

                      itvpt_pb.stop();

                    }

                     

                     

                    itvcare_pb.addEventListener(Event.REMOVED_FROM_STAGE,itvcare_f);

                    function itvcare_f(e:Event):void{

                      itvcare_pb.stop();

                    }

                     

                    I went and I ran my movie and I got the following errors:

                    [SWF] HZN105_Large_Screen.swf - 856952 bytes after decompression

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

                      at HZN105_Large_Screen_fla::MainTimeline/frame1()[HZN105_Large_Screen_fla.MainTimeline::fram e1:30]

                    [SWF] MinimaFlatCustomColorPlayBackSeekCounterVolMute.swf - 32044 bytes after decompression

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

                      at HZN105_Large_Screen_fla::MainTimeline/frame1()[HZN105_Large_Screen_fla.MainTimeline::fram e1:30]

                      at flash.display::MovieClip/gotoAndPlay()

                      at HZN105_Large_Screen_fla::MainTimeline/homeBtn()[HZN105_Large_Screen_fla.MainTimeline::fra me1:11]

                    [UnloadSWF] HZN105_Large_Screen.swf

                    Test Movie terminated.

                     

                    What am I doing wrong? I really need help please!!!

                    • 7. Re: How to stop videos using Action Script?
                      kglad Adobe Community Professional & MVP

                      you're trying to reference those flvplayback instances in frame 1 and they don't all exist in frame 1.

                       

                      you should put the code i showed in the keyframe where the flvplaybacks exist.

                      • 8. Re: How to stop videos using Action Script?
                        JacquelineSebrey Level 1

                        I went and added the above code in to Frame 10, Frame 20, Frame 30, and Frame 40 and when I saved and ran everything seemed to work but I got the following error:

                         

                        [SWF] HZN105_Large_Screen.swf - 861725 bytes after decompression

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

                          at HZN105_Large_Screen_fla::MainTimeline/frame10()[HZN105_Large_Screen_fla.MainTimeline::fra me10:36]

                          at flash.display::MovieClip/gotoAndPlay()

                          at HZN105_Large_Screen_fla::MainTimeline/selmaBtn()[HZN105_Large_Screen_fla.MainTimeline::fr ame1:14]

                        [SWF] MinimaFlatCustomColorPlayBackSeekCounterVolMute.swf - 32044 bytes after decompression

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

                          at HZN105_Large_Screen_fla::MainTimeline/frame20()[HZN105_Large_Screen_fla.MainTimeline::fra me20:30]

                          at flash.display::MovieClip/gotoAndPlay()

                          at HZN105_Large_Screen_fla::MainTimeline/timBtn()[HZN105_Large_Screen_fla.MainTimeline::fram e1:18]

                        [SWF] MinimaFlatCustomColorPlayBackSeekCounterVolMute.swf - 32044 bytes after decompression

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

                          at HZN105_Large_Screen_fla::MainTimeline/frame30()[HZN105_Large_Screen_fla.MainTimeline::fra me30:30]

                          at flash.display::MovieClip/gotoAndPlay()

                          at HZN105_Large_Screen_fla::MainTimeline/itvptBtn()[HZN105_Large_Screen_fla.MainTimeline::fr ame1:22]

                        [SWF] MinimaFlatCustomColorPlayBackSeekCounterVolMute.swf - 32044 bytes after decompression

                        [UnloadSWF] HZN105_Large_Screen.swf

                        Test Movie terminated.

                         

                        I went and added the code for the buttons in to Frame 10, Frame 20, Frame 30, and Frame 40 and when I saved and ran everything it still seemed to sort of work but I again received the above error message. My complete code for Frame 10 as an example is:

                         

                        import flash.events.Event;

                        import flash.events.MouseEvent;

                         

                         

                        home.addEventListener(MouseEvent.CLICK,homeBtn1);

                        selma.addEventListener(MouseEvent.CLICK,selmaBtn1);

                        tim.addEventListener(MouseEvent.CLICK,timBtn1);

                        itvpt.addEventListener(MouseEvent.CLICK,itvptBtn1);

                        itvcare.addEventListener(MouseEvent.CLICK,itvcareBtn1);

                         

                         

                        function homeBtn1(event:MouseEvent){

                          gotoAndPlay("home");

                        }

                         

                         

                        function selmaBtn1(event:MouseEvent){

                          gotoAndPlay("selma");

                        }

                         

                         

                        function timBtn1(event:MouseEvent){

                          gotoAndPlay("tim");

                        }

                         

                         

                        function itvptBtn1(event:MouseEvent){

                          gotoAndPlay("itvpt");

                        }

                         

                         

                        function itvcareBtn1(event:MouseEvent){

                          gotoAndPlay("itvcare");

                        }

                         

                         

                        selma_pb.addEventListener(Event.REMOVED_FROM_STAGE,selma_f);

                        function selma_f(e:Event):void{

                          selma_pb.stop();

                        }

                         

                         

                        tim_pb.addEventListener(Event.REMOVED_FROM_STAGE,tim_f);

                        function tim_f(e:Event):void{

                          tim_pb.stop();

                        }

                         

                         

                        itvpt_pb.addEventListener(Event.REMOVED_FROM_STAGE,itvpt_f);

                        function itvpt_f(e:Event):void{

                          itvpt_pb.stop();

                        }

                         

                         

                        itvcare_pb.addEventListener(Event.REMOVED_FROM_STAGE,itvcare_f);

                        function itvcare_f(e:Event):void{

                          itvcare_pb.stop();

                        }

                         

                        I feel like I am almost there and I can just taste it. Please look over the error message and my code for Frame 10 where the video instance "selma" occurs. Thank you so much for your help!!!

                        • 9. Re: How to stop videos using Action Script?
                          JacquelineSebrey Level 1

                          I did it!!!

                           

                          I had too much code. I just needed to put in the code to stop the video for the frame that contained that video. Not the code for ALL of the videos just the code for that one!!! When I went and deleted the extra code and I saved my file and tested it. It worked!!! The videos stop when you click on another button!!! It's awesome!!!

                           

                          So the code for say just Frame 10 which contains the first video should be:

                           

                          selma_pb.addEventListener(Event.REMOVED_FROM_STAGE,selma_f);

                          function selma_f(e:Event):void{

                            selma_pb.stop();

                          }

                           

                          You just change the name(s) or label name(s) for each video and just put it in the frame of that particular video and it will work just fine!!! What a relief!!! Thank you so much for your insight and assistance!!! I can't wait to inform my customer and upload the files for him to test out and see how they work!!!!

                          • 10. Re: How to stop videos using Action Script?
                            kglad Adobe Community Professional & MVP

                            you're welcome.

                             

                            p.s when using the adobe forums, please mark helpful/correct responses, if there are any.

                            • 11. Re: How to stop videos using Action Script?
                              JacquelineSebrey Level 1

                              I don’t know your name except you go by glad. I’m Jackie by the way. I need some more help with this project that I’m working on and I was wondering if you wouldn’t mind helping me out. If you don’t mind please email me back at jackiesebrey@me.com <mailto:jackiesebrey@me.com> and I’ll hopefully be looking for an email response from you. There’s something a little challenging that my customer wants me to do and it involves videos and while a video is playing you click a button that shows up text and the video you were on should be automatically paused and the text should show up on the screen over the video and when you are done with the text on the screen and click the close button it should take you back to the video and resume playing from when it was paused to look at text. I have no idea as to how to do this and would appreciate so help. Thank you and take care.

                               

                              Jackie

                              • 12. Re: How to stop videos using Action Script?
                                JacquelineSebrey Level 1

                                By the way, I’m a Boilermaker too!!! Class of 2012!!!

                                 

                                Please contact me. This is my first official project I’m doing as a professional and I’m really nervous and right now my customer is not too happy with my work and he also wants me to do something that I’ve never done before and don’t even know if it can be done. Please contact me either via email at: jackiesebrey@me.com <mailto:jackiesebrey@me.com> or via home phone at 302-543-4144 or via cell phone at 302-740-4551. I really could use some professional assistance to successfully complete my first professional project and I think my problem is mostly dealing with confidence. I hope that you can understand and empathize and go back to your first professional project that you did and how overwhelming it can be. Thank you again for helping me out with the videos!!! Your guidance what spot on and I did have a moment of serendipity which did help. You are also the first Flash Professional that I have come across. I have taken 3 classes on Flash in college and I have close to two dozen books on Flash alone. I like it, I just don’t like it when I don’t know how to do something. That drives me nuts. If you could call me I would really appreciate it. Especially since we are both Boilermakers!!!

                                 

                                Jackie