5 Replies Latest reply on Feb 5, 2013 3:47 PM by kglad

    Pause/Play for external SWF

    CEItim Level 1

      Can anyone help me witht this? I've been going crazy trying to figure it out because nothing is working out. I am trying to create a pause/play button that will pause and play everything on the main timeline (easy), as well as an external SWF that is being loaded with the Loader class. Here is my code:

       

      var myLoader:Loader = new Loader();                 // create a new instance of the Loader class

      var url:URLRequest = new URLRequest("MYCONTENT.swf");

      myLoader.load(url);                                 // load the SWF file

      myLoader.x = 134;

      myLoader.y = 148;

      addChild(myLoader);

       

      On the main timeline I have a MovieClip that is the Pause/Play button. It toggles between the two. How do I get it to control the external SWF as well?

       

      On Frame 1:

      stop();

       

      pauseBtn.addEventListener(MouseEvent.CLICK, pauseMovie);

       

      function pauseMovie(e:Event): void {

          gotoAndStop(2);

           MovieClip(root).stop();

          MovieClip(root).myLoader.content.stop();  ///??????????

          }

       

      On frame 2:

      playBtn.addEventListener(MouseEvent.CLICK, playMovie);

      function playMovie(e:Event): void {

          gotoAndStop(1);

           MovieClip(root).play();

          MovieClip(root).myLoader.content.play();  ///????????????

      }

        • 1. Re: Pause/Play for external SWF
          kglad Adobe Community Professional & MVP

          if myLoader is on the root timeline, use:

           

           

           

          var myLoader:Loader = new Loader();                 // create a new instance of the Loader class

          var url:URLRequest = new URLRequest("MYCONTENT.swf");

          myLoader.load(url);                                 // load the SWF file

          myLoader.x = 134;

          myLoader.y = 148;

          addChild(myLoader);

           

          On the main timeline I have a MovieClip that is the Pause/Play button. It toggles between the two. How do I get it to control the external SWF as well?

           

          On Frame 1:

          stop();

           

          pauseBtn.addEventListener(MouseEvent.CLICK, pauseMovie);

           

          function pauseMovie(e:Event): void {

              gotoAndStop(2);

               MovieClip(root).stop();

              MovieClip(root.myLoader.content).stop();  ///??????????

              }

           

          On frame 2:

          playBtn.addEventListener(MouseEvent.CLICK, playMovie);

          function playMovie(e:Event): void {

              gotoAndStop(1);

               MovieClip(root).play();

              MovieClip(root.myLoader.content).play();  ///????????????

          }

          1 person found this helpful
          • 2. Re: Pause/Play for external SWF
            CEItim Level 1

            Thanks for your help. I tried it but I got this error:

             

            Symbol 'playPause', Layer 'actions', Frame 1, Line 91119: Access of possibly undefined property myLoader through a reference with static type flash.display:DisplayObject.
            • 3. Re: Pause/Play for external SWF
              kglad Adobe Community Professional & MVP

              try:

               

               

               

               

               

              var myLoader:Loader = new Loader();                 // create a new instance of the Loader class

              var url:URLRequest = new URLRequest("MYCONTENT.swf");

              myLoader.load(url);                                 // load the SWF file

              myLoader.x = 134;

              myLoader.y = 148;

              addChild(myLoader);

               

              On the main timeline I have a MovieClip that is the Pause/Play button. It toggles between the two. How do I get it to control the external SWF as well?

               

              On Frame 1:

              stop();

               

              pauseBtn.addEventListener(MouseEvent.CLICK, pauseMovie);

               

              function pauseMovie(e:Event): void {

                  gotoAndStop(2);

                   MovieClip(root).stop();

                  MovieClip(MovieClip(root).myLoader.content).stop();  ///??????????

                  }

               

              On frame 2:

              playBtn.addEventListener(MouseEvent.CLICK, playMovie);

              function playMovie(e:Event): void {

                  gotoAndStop(1);

                   MovieClip(root).play();

                  MovieClip(MovieClip(root).myLoader.content).play();  ///????????????

              }

              • 4. Re: Pause/Play for external SWF
                CEItim Level 1

                That fixed the error at runtime, but the pause does not work.

                 

                When I pressed the pause button, I got this error in the console:

                 

                TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@2a2080f9 to flash.display.MovieClip.

                    at MyProject_fla::playPause_5/pauseMovie()

                • 5. Re: Pause/Play for external SWF
                  kglad Adobe Community Professional & MVP

                  you're loading an as2 swf into an as3 swf.  you can't directly control the as2 swf.

                   

                  you must use localconnection to communicate between the two:  http://kb2.adobe.com/community/publishing/918/cpsid_91887.html

                  1 person found this helpful