14 Replies Latest reply on Jun 1, 2010 1:29 PM by kglad

    HELP: AS2 Play button to launch rtmp movie

    rougemarsha1

      Hello All,

       

      I have an .fla created with a single key frame.  In the frame I have a button instance (its own layer), a layer called "act" where my actionscript is entered, and an swf FLVPlayback instance (its own layer).

       

      I simply want the button to show when launched, upon being clicked to launch my movie, and the button to disapear.  My FLVPlayback points to an rmtp stream that works fine and is setup to autoplay = true.

       

      currently I am using this code but the button doesn't disappear and the movie begins to play before the button is pressed.  I have also switched the movie to autoplay = false but pressing the button does not play the movie.

       

      any help would be great and most appreciated!!!

       

      the code on the "act" layer is (my_btn is the button and my_mc is the movie):

       

      my_btn.addEventListener(MouseEvent.CLICK, btnClicked);
      function btnClicked(e:MouseEvent):void{
      my_mc.play();
      }

        • 1. Re: HELP: AS2 Play button to launch rtmp movie
          kglad Adobe Community Professional & MVP

          that's as3.  are you publishing for as2 or as3?


          • 2. Re: HELP: AS2 Play button to launch rtmp movie
            rougemarsha1 Level 1

            my apologies; I thought that was AS2.  To be honest, I don't really understand the difference between the two and have no preference on which one I use; as long as it works.

             

            Would you have a recommendation either way and/or help in how to pull this off in either one?

             

            thanks so much for your help.

            • 3. Re: HELP: AS2 Play button to launch rtmp movie
              kglad Adobe Community Professional & MVP

              either is fine as long as the code you use matches your publish settings and the component you use is appropriate for your publish settings.

               

              so, if you're publishing for as3 and have an as3 flvplayback component on stage assign the component an instance name (eg, flv), assign its autoplay property to false and use:

               

              my_btn.addEventListener(MouseEvent.CLICK, btnClicked);  // assuming my_btn is the instance name of your button.
              function  btnClicked(e:MouseEvent):void{
              flv.play();
              }

              • 4. Re: HELP: AS2 Play button to launch rtmp movie
                rougemarsha1 Level 1

                looks like that worked for me!  At least I have a functional script I can begin "tweaking" now.  Thanks for all

                your help!

                • 6. Re: HELP: AS2 Play button to launch rtmp movie
                  rougemarsha1 Level 1

                  seems one question leeds to the next:

                   

                  Now that I have it working I need to modify the page and have several video windows on the page so the user can play whichever one they wish.

                   

                  I thought it would be a simple matter of copying the FLVPlayback instance and the my_btn instance, pasting them in another area, modifying their instance names and updating the actionscript.  I'm sure I just don't have this correct as the published page has the play arrows but no video window and the play buttons don't play the video as before.

                   

                  Can you see what is wrong with the script?:

                   

                  my_btn.addEventListener(MouseEvent.CLICK, btnClicked);  // assuming my_btn is the instance name of your button.
                  function  btnClicked(e:MouseEvent):void{
                      flv.play();
                  }
                  my_btn2.addEventListener(MouseEvent.CLICK,btnClicked);  // assuming my_btn is the instance name of your button.
                  function  btnClicked(e:MouseEvent):void{
                      flv2.play();
                  }

                  • 7. Re: HELP: AS2 Play button to launch rtmp movie
                    kglad Adobe Community Professional & MVP

                    do you see any error messages before or after you click my_btn2?

                    • 8. Re: HELP: AS2 Play button to launch rtmp movie
                      rougemarsha1 Level 1

                      Yes,

                       

                      here is the error and it states line 6 of the code

                       

                      ERROR:

                       

                      1021: Duplicate function definition.

                      function  btnClicked(e:MouseEvent):void{

                       

                      ACTION:

                       

                      1  my_btn.addEventListener(MouseEvent.CLICK,btnClicked);  // assuming my_btn is the instance name of your button.
                      2  function  btnClicked(e:MouseEvent):void{
                      3     flv.play();
                      4  }
                      5  my_btn2.addEventListener(MouseEvent.CLICK,btnClicked);  // assuming my_btn is the instance name of your button.
                      6  function  btnClicked(e:MouseEvent):void{
                      7     flv2.play();

                      • 9. Re: HELP: AS2 Play button to launch rtmp movie
                        kglad Adobe Community Professional & MVP

                        that's pretty easy to understand.  rename your functions and have each button call the correct function.

                        • 10. Re: HELP: AS2 Play button to launch rtmp movie
                          rougemarsha1 Level 1

                          yes; seems to be working now as I did some searching and did rename the functions:

                           

                          my_btn.addEventListener(MouseEvent.CLICK,btnClicked1);  // assuming my_btn is the instance name of your button.
                          function btnClicked1(e:MouseEvent):void {
                              flv.play();
                          }
                          my_btn2.addEventListener(MouseEvent.CLICK,btnClicked2);  // assuming my_btn is the instance name of your button.
                          function btnClicked2(e:MouseEvent):void {
                              flv2.play();
                          }

                           

                           

                          Now I'm working on getting an image placeholder for each movie as their both black until either is started.  Any ideas on how to do that would be great.

                           

                          thanks again!!

                          • 11. Re: HELP: AS2 Play button to launch rtmp movie
                            kglad Adobe Community Professional & MVP

                            use google to search for: flash <your cs version> poster frame tutorial.

                            • 12. Re: HELP: AS2 Play button to launch rtmp movie
                              rougemarsha1 Level 1

                              Hi again Kglad,

                               

                              I do have the poster frame working but the issue is I need two poster frames, one for each video window.

                               

                              In the code below I show no compile errors but the second posterframe doesn't disappear when the play button is pressed.  Not sure how to modify to get it to work.  If you see any obvious issue, I would love to hear it (red is new poster frame code).

                               

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

                               

                              import fl.video.VideoEvent;
                              my_btn.addEventListener(MouseEvent.CLICK,btnClicked1);  // assuming my_btn is the instance name of your button.
                              function btnClicked1(e:MouseEvent):void {
                                  flv.play();
                              }
                              my_btn2.addEventListener(MouseEvent.CLICK,btnClicked2);  // assuming my_btn is the instance name of your button.
                              function btnClicked2(e:MouseEvent):void {
                                  flv2.play();
                              }
                              function showPosterFrame(event:Event):void {  //start of Poster Frame code
                                  myPoster.visible = true;
                              }

                              function hidePosterFrame(event:Event):void {
                                  myPoster.visible = false;
                              }
                              flv.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, hidePosterFrame);
                              flv.addEventListener(VideoEvent.COMPLETE, showPosterFrame);  //end of poster frame code

                              function showPosterFrame2(event:Event):void {  //start of Poster Frame code
                                  myPoster2.visible = true;
                              }

                              function hidePosterFrame2(event:Event):void {
                                  myPoster2.visible = false;
                              }
                              flv2.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, hidePosterFrame);
                              flv2.addEventListener(VideoEvent.COMPLETE, showPosterFrame);  //end of poster frame code

                              • 13. Re: HELP: AS2 Play button to launch rtmp movie
                                rougemarsha1 Level 1

                                disregard Kglad, I just notice the issue with the last two lines of code; forgot to refere to PosterFrame2.

                                 

                                flv2.addEventListener(VideoEvent.PLAYING_STATE_ENTERED,  hidePosterFrame);
                                flv2.addEventListener(VideoEvent.COMPLETE,  showPosterFrame);  //end of poster frame code

                                 

                                thanks for your help!