7 Replies Latest reply on May 17, 2010 1:51 AM by celebritymusic

    Problem loading and displaying a swf

    celebritymusic Level 1

      Hi

       

      I have six buttons, and I want each one to display a corresponding externally loaded swf, 01.swf, 02.swf.

       

      It works fine, except that sometimes swfs load up, and sometimes they don't.  For example, if I hit button 6, the 06.swf loads.  but if I hit button 6 after hitting 3 other buttons, SOMETIMES 06.swf loads, other times it doens't and I get an error that relates to the removeChild

       

       

       

      var loader2:Loader = new Loader();

       


      function showVid (evt): void {

       

      if (e1.data.childAdded2 == true) {this.removeChild(loader2);};

       

      loader2.load(new URLRequest("videos/"+e1.data.question_num+".swf"));
      loader2.x=-270;
      loader2.y=-155;
      loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, displayVideo);

       

      function displayVideo (event:Event): void {
      addChild(loader2);
      e1.data.childAdded2 = true;
      }

       

      }

        • 1. Re: Problem loading and displaying a swf
          kglad Adobe Community Professional & MVP

          1.  your add/remove does nothing useful

          2.  never nest named functions

          3.  use:

           


           

           

          var loader2:Loader = new Loader();

          addChild(loader2);

           


          function showVid (evt): void {

           

           

          loader2.load(new URLRequest("videos/"+e1.data.question_num+".swf"));
          loader2.x=-270;
          loader2.y=-155;
          loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, displayVideo);

           

          }


          function displayVideo (event:Event): void {}

          • 2. Re: Problem loading and displaying a swf
            celebritymusic Level 1

            Thanks kglad

             

            My apologies for not finishing off my first post - I wasn't concentrating when I hit submit.

             

            I'm still having a problem getting the videos to show after hitting the buttons a few times.

             

            For example, if I hit button 1 a number of times in a row, 01.swf loads and plays the first four or five times, but then it won't display.  Sometimes it's less than this many button hits.  And likewise if I hit different buttons randomly.

             

            I've trimmed the code down some more:

             

            var loader2:Loader = new Loader();

            addChild(loader2);

             


            function  showVid (evt): void {

             

            loader2.load(new  URLRequest("videos/"+e1.data.question_num+".swf"));
            loader2.x=-270;
            loader2.y=-155;

            }


            Any idea why?  It feels like a Flash bug.

             

            Cheers kglad.

            • 3. Re: Problem loading and displaying a swf
              kglad Adobe Community Professional & MVP

              use the trace() function to see what you're doing:

               


               

              var loader2:Loader = new Loader();

              addChild(loader2);

               


              function  showVid (evt): void {

                trace("videos/"+e1.data.question_num+".swf")

              loader2.load(new  URLRequest("videos/"+e1.data.question_num+".swf"));
              loader2.x=-270;
              loader2.y=-155;

              }



              1 person found this helpful
              • 4. Re: Problem loading and displaying a swf
                celebritymusic Level 1

                That returns videos/01.swf (number of swf depends on button hit).

                 

                If I hit button 1 over and over, it keeps returning...

                 

                videos/01.swf

                videos/01.swf

                videos/01.swf

                videos/01.swf

                videos/01.swf

                 

                but eventually it stops displaying the video after it starts playing it 3 or 4 times.

                 

                I thought it might have been a case of too many instances of video, but the old code was removing the video each time (I tested it too make sure it was), and the problem stilll occured.

                 

                Have you seen anything like this before?  It's a strange one.

                • 5. Re: Problem loading and displaying a swf
                  kglad Adobe Community Professional & MVP

                  is flash video (an flv) played in 01.swf?

                   

                  and the trace() returns that value even when the swf no longer loads?  and what do you see that makes you think a swf does not load?

                  1 person found this helpful
                  • 6. Re: Problem loading and displaying a swf
                    celebritymusic Level 1

                    I've converted the videos from avi's to .swfs using Bikisoft Total Video Converter.

                     

                    I might try converting them to flvs.

                     

                    And yes, the trace continues to return the correct string, even when the video doesn't play.

                    • 7. Re: Problem loading and displaying a swf
                      celebritymusic Level 1

                      Sorry kglad - I haven't worked on this all week.

                       

                      To answer your question about what makes me think the viodeo isn't loading, is that nothing shows up - the stage background just stays black.  Maybe it is loading, but just not playing?

                       

                      Any ideas?

                       

                      Cheers

                       

                      Shaun