12 Replies Latest reply on Dec 24, 2013 9:06 AM by sinious

    Preload a .SWF with Javasript?

    thanser Level 1

      Does it have any effect on the playback of a .swf?

       

      What if I simply use a script like this?

       

      <script type="text/javascript">

      if (document.images) {

          img1 = new Image();

          img1.src = "presentation.swf";

      }

      </script>

       

      I've noticed that my .swf performs better after playing it once - I assume this is due to the fact that's it's been downloaded and cached by the browser...?

       

      http://www.thomashanserdesign.com#flash

       

      For a short Flash piece like this, I'm not going to bother with a Flash "preloader." I just thought using a Javascript would load the .swf in its entirety and help improve the performance.  (It tends to slow down near the end of the video, before the logo appears at the end.)

       

      Comments?

        • 1. Re: Preload a .SWF with Javasript?
          sinious Most Valuable Participant

          I haven't come across loading a SWF in this way but it's bound to be buggy or simply fail compliance. A SWF is not an image. You should use some traditional practices such as load the SWF normally but hide it and simply tell it when to appear and play with traditional JS/CSS. It should be wrapped in an <object> tag.

           

          Do you simply want it to play once it's completely loaded or when you specifically want it to play?

          1 person found this helpful
          • 2. Re: Preload a .SWF with Javasript?
            kglad Adobe Community Professional & MVP

            no, that won't preload the swf any more than your embedding code.

            1 person found this helpful
            • 3. Re: Preload a .SWF with Javasript?
              thanser Level 1

              Thanks, everyone.

               

              All I want to do is improve the playback performance, so it doesn't stutter halfway through. I noticed it DOES play well on the second try. I've tried loading the video dynamically as an MC, but it chokes for a moment while the video starts, so I decided to try embedding the video (frame by frame), which is what you're seeing now.

               

              I never cared to see a progress bar while something loads on a web page. This presentation is small, so why use an AS3 preloader script?

               

              (It's been many years since I did Flash pieces or presentations, and I want to keep my skills polished and at least one piece in my portfolio.)

               

              Thanks again.

              • 4. Re: Preload a .SWF with Javasript?
                sinious Most Valuable Participant

                The second try is simply the cache as you've noticed. You're much better off keeping the video external, using a mobile friendly format like MP4 and utilizing the NetStream buffer system. If you really want it to work well and be polished, you can't avoid things like this.

                 

                Embedding the video not only makes it device unfriendly but it uses inferior codecs so your video quality will take the penalty of quality or file size.

                 

                You should do some feature detection for native HTML5 <video> support and use the built in player, otherwise fall back to the SWF. You can detect that support with the Modernizr library and there's a ton of free video players out there that will do all of this for you automatically.

                 

                Bandwidth definitely comes into play here. My meter showed me on a 100mbit line I loaded your SWF in about ~0.3 seconds. BTW the product looks good, how many ANSI lumens is it?

                • 5. Re: Preload a .SWF with Javasript?
                  thanser Level 1

                  Flash isn't mobile friendly (in terms of using an Apple product) so it's a moot point.  I had the .flv video file loading dynamically (as an MC) but it choked during playback when it came time to load it.  Embedding works better in this case.

                   

                  Bandwidth: This is located on a GoDaddy.com server, so...it may not be the fastest server available.

                   

                  I doubt I'll get any new Flash work, but I wanted it to be in my portfolio.

                   

                  ANSI Lumens?  Who cares?  They laid off me and the whole sales and marketing team in 2009.

                   

                  Thanks, everyone.

                  • 6. Re: Preload a .SWF with Javasript?
                    sinious Most Valuable Participant

                    Ack, sorry to hear that.

                     

                    As a portfolio you're going to want to be as up to date as possible. I'm not saying that you shouldn't keep a SWF player in your back pocket as a fallback but to show your skill set is modern you really should play that piece as a HTML5 <video> if the users browser supports it. Then all devices will be able to see it.

                     

                    Good luck in the future!

                    1 person found this helpful
                    • 7. Re: Preload a .SWF with Javasript?
                      thanser Level 1

                      Thanks, Sinious. 

                       

                      If I were smart, I'd dump the .swf and create this presentation again in HTML5, indeed.  I prefer After Effects but it's not interactive, of course.

                       

                      I could never get the video just right - it always paused or blinked when it started.

                       

                      Thanks again.

                      • 8. Re: Preload a .SWF with Javasript?
                        sinious Most Valuable Participant

                        Even just export it as a video just how it is (there are plenty of free SWF to video converters out there). Then compress the video it creates to MP4 and use any free video player that will auto-fallback to SWF. Shouldn't take you more than 45 minutes to convert, compress and use one of the many open source video players. If you need a hand compressing the final video I can compress it with Sorenson Squeeze as best it can be so it retains perfect quality but is very small file size. Just let me know if you need a hand.

                        1 person found this helpful
                        • 9. Re: Preload a .SWF with Javasript?
                          kglad Adobe Community Professional & MVP

                          or use flash (cs6 or cc) to create an html5 using your fla.  if there's no actionscript (and there doesn't appear to be any), the html5 should be satisfactory.

                          • 10. Re: Preload a .SWF with Javasript?
                            thanser Level 1

                            Thanks, Sinious.

                             

                            I see what you mean, by using an .MP4 instead of a .SWF file.  I can do that here at home, actually, but I lose the interactivity.

                             

                            I'm not going to put a lot of effort into deprecated technologies, I suppose.  I just wanted to show a simple Flash ad in portfolio.

                             

                            Thanks again.

                            • 11. Re: Preload a .SWF with Javasript?
                              thanser Level 1

                              Thank you, kglad.

                               

                              I've never used Flash for HTML5 but I'll look into it.

                              • 12. Re: Preload a .SWF with Javasript?
                                sinious Most Valuable Participant

                                Kglad's suggestions is good for you then. I thought you wanted to showcase merely what I see when I press play but if you want to retain interactivity, depending on your version of Flash you may have the ability to convert to HTML5. CS6 uses an extension, the CreateJS toolkit (Shift+F9 or Window->Toolkit for CreateJS) or CC has it integrated a bit deeper (Commands->Convert to HTML5 Canvas from AS3 document formats). Then your project is actually converted to a canvas project. Hopefully your scripting was light enough to be converted successfully.