yixiaohui12345 / swfobject

Automatically exported from code.google.com/p/swfobject
0 stars 0 forks source link

Allow option to see alternative content (e.g. background image) while waiting for the swf file to load. Thanks! #277

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Allow option to see alternative content (e.g. background image) while 
waiting for the swf file to load. Thanks!

Original issue reported on code.google.com by daj...@gmail.com on 7 Mar 2009 at 7:44

GoogleCodeExporter commented 9 years ago
That would be cool.

Original comment by poschi...@gmail.com on 8 Mar 2009 at 10:41

GoogleCodeExporter commented 9 years ago
The option not to use dynamic CSS to hide alternative content was already on our
internal dev list :-)

Original comment by bobbyvandersluis on 9 Mar 2009 at 9:27

GoogleCodeExporter commented 9 years ago
Cool! I can't wait for the next release with that feature. The only reason I 
still 
use adobe AC_FL_RunContent() is solely for that reason. =)

Original comment by daj...@gmail.com on 9 Mar 2009 at 5:23

GoogleCodeExporter commented 9 years ago

Original comment by bobbyvandersluis on 1 Apr 2009 at 10:01

GoogleCodeExporter commented 9 years ago
a developer can now switch off SWFObject's default hide/show behavior via
swfobject.switchOffAutoHideShow()

Original comment by bobbyvandersluis on 3 Apr 2009 at 1:02

GoogleCodeExporter commented 9 years ago
A nice addition to this would be the ability to have a separate div assigned to 
the
content that is visible to the user in the case that they are waiting for a swf 
to
load. This would allow for alternative content for text-based browsers and SEO, 
and
also a custom image / other content for users waiting for the SWF to load. The 
div id
for the content that should be shown while waiting for the swf could be passed 
to the
switchOffAutoHideShow as a parameter perhaps.

Original comment by ebr...@gmail.com on 6 Apr 2009 at 6:29

GoogleCodeExporter commented 9 years ago
Included in the SWFObject 2.2 beta1 release

Original comment by bobbyvandersluis on 16 Apr 2009 at 3:05

GoogleCodeExporter commented 9 years ago
The problem is there seems to be a delay now between the time the alternative 
content disappears and the flash appears.

In other words, it's:
1) Alternative content appears.
2) Alternative content disappears.
3) Delay.
4) Flash appears.

Step #1 and #3 should be the same step.

I've tried it with with multiple large sized SWF files.

Original comment by lwc4...@gmail.com on 13 Jun 2009 at 6:48

GoogleCodeExporter commented 9 years ago
Re 8: It now emulates AC_FL_RunContent and the old SWFObject 1.x libraries. To 
minize
this delay you can use a small loader SWF to load bigger SWFs.

Original comment by bobbyvandersluis on 13 Jun 2009 at 7:28

GoogleCodeExporter commented 9 years ago
Isn't the whole point of this feature to eliminate the need for preloaders? And 
if 
it's a new feature how does it emulate old libraries?

Anyway, I don't have the original FLA and the SWF file needs flashvars and 
other 
parameters which I have no way to pass without directly calling the SWF file 
from 
the HTML. So I thought the new feature would do the trick.

Thanks!

Original comment by lwc4...@gmail.com on 13 Jun 2009 at 8:12

GoogleCodeExporter commented 9 years ago
Aha, we described it incorrectly on our new features page, our apologies for 
that:

"Developers now have the option to display alternative content (e.g. background
image) while waiting for the swf file to load by switching off SWFObject's 
default
hide/show behavior."

has become:

Developers now have the option to switch off SWFObject's default hide/show 
behavior
(SWFObject temporarily hides your SWF or alternative content until the library 
has
decided which content to display).

The reason for this is that many developers don't like the default usage of 
dynamic
CSS to temporarily hide content.

Original comment by bobbyvandersluis on 13 Jun 2009 at 8:34

GoogleCodeExporter commented 9 years ago
We will review this feature for the next cycle:
- dynamic publishing only, wait until the swf file has loaded (or has started
playing?) for the actual replacement
- or, like suggested in comment 6, have a separate div assigned to the content 
that
is visible to the user in the case that they are waiting for a swf to load

Original comment by bobbyvandersluis on 13 Jun 2009 at 8:50

GoogleCodeExporter commented 9 years ago
I can't wait for it to really be a preloader.

But shouldn't it be "SWFObject temporarily hides your SWF *and* alternative 
content" 
(and by using this feature it hides only the former)?

Original comment by lwc4...@gmail.com on 13 Jun 2009 at 8:59

GoogleCodeExporter commented 9 years ago
OR, because you either use static or dynamic publishing, so one of these two 
will be
the initial content.

Original comment by bobbyvandersluis on 14 Jun 2009 at 10:06

GoogleCodeExporter commented 9 years ago
Diziler http://www.turkdizi.tv/ http://www.turkdizi.tv/kolej-gunlugu/ 
http://www.turkdizi.tv/duz-adam/ http://www.turkdizi.tv/yeniden-basla/ 
http://www.turkdizi.tv/karakol/ http://www.turkdizi.tv/basrolde-ask/

Original comment by xdag...@gmail.com on 21 Apr 2011 at 11:03

GoogleCodeExporter commented 9 years ago
Marking this as "wontfix" because the requested functionality is already 
possible without modifying the SWFObject library. Plus there are a gazillion 
different approaches that can be taken, and we don't want to assume one over 
another.

An example is provided below. The sample code performs the following tasks:

1. Creates a new off-screen <div> for embedding the SWF.

2. Checks to see if SWFObject was successful embedding into the new <div>. If 
not, the fallback content is left as-is.

3. Checks to see if the SWF is loading. 
     -- If the SWF is loading, the fallback content is hidden, and an HTML-based preloader is inserted into the page.
     -- If the SWF is not loading (not found), the fallback content is restored and the <object> generated by SWFObject is deleted.

 4. Sets an interval to check if the SWF has finished loading. Upon completion, the HTML-based preloader is deleted and the <object> generated by SWFObject is given the ID of the original target element.

I'm sure the script could use some cleaning up, but it's provided purely as an 
example of what can be done with SWFObject. This script has been successfully 
tested with SWFObject 2.2 in IE7, IE9, Firefox 4, Safari 5, Chrome 11 and Opera 
11.

    var targetElementID = "myContent";
    var tempID = targetElementID + "-temp";
    var targetEl;

    var callback = function (e){

       if(e.success && e.ref){

          var initialTimeout = setTimeout(function (){

             if(typeof e.ref.PercentLoaded !== "undefined" && e.ref.PercentLoaded()){

                //Insert HTML preloader. Can be whatever you want
                var preloader = document.createElement("div");
                preloader.innerHTML = "Loading SWF, please wait...";
                e.ref.parentNode.appendChild(preloader);

                var loadCheckInterval = setInterval(function (){

                    if(e.ref.PercentLoaded() === 100){

                        //Clear timer
                        clearInterval(loadCheckInterval);

                        //Remove HTML preloader
                        e.ref.parentNode.removeChild(preloader);

                        //Remove ALT content
                        targetEl.parentNode.removeChild(targetEl);

                        //Set SWFObject ID to be same as original target
                        //This clears CSS rules associated with tempID.
                        e.ref.setAttribute("id", targetElementID);

                    }

                }, 1500);

             } else {

                //Remove the SWF <object> since the SWF can't be loaded
                e.ref.parentNode.removeChild(e.ref);

                //Restore the ALT content
                targetEl.style.display = "block";

             }

            clearTimeout(initialTimeout);

          }, 200);

       } else {

            //Delete the DIV we just created.
            var temp_div = document.getElementById(tempID);
            temp_div.parentNode.removeChild(temp_div);

       }

    };

    //Set CSS properties to ensure generated <div> and <object> remain hidden
    swfobject.createCSS("#" +tempID, "position: absolute; left: -999em;");

    swfobject.addDomLoadEvent(function (){

        targetEl = document.getElementById(targetElementID);

        //Temporarily hide the ALT content
        targetEl.style.display = "none";

        //Create DIV for embedding SWF
        var div = document.createElement("div");

        //Provide an ID
        div.setAttribute("id", tempID);        

        //Append to page just after target element
        targetEl.parentNode.appendChild(div);

        //Embed SWF in new <div>
        swfobject.embedSWF("test2.swf", tempID, "300", "120", "8.0.0", "expressInstall.swf", false, false, false, callback);

    });

Original comment by platelu...@gmail.com on 1 Jun 2011 at 12:06

GoogleCodeExporter commented 9 years ago
Thank you platelu...@gmail.com for your solution. But I don't understand why 
you closed the request as "won't fix". The approach you described is way too 
flaky. It is very sensitive to the "timeout", and depending on what the value 
is set to, it may or may not work in one browser or another. Besides, even 
worse, you may even see "weird" behavior. For example, if you put in myContent 
some content that takes time to load (like the image of Adobe Flash logo, the 
result is that the fallback content is first shown, then the Flash object 
becomes visible at the same time as the "wait" message.
After all, isn't the whole point of using swfObject to avoid having to write 
all this code in the first place?

Original comment by fzarrink...@nexon.net on 19 Sep 2011 at 11:36

GoogleCodeExporter commented 9 years ago
The point of SWObject is to replace the HTML with a SWF using standards-based 
markup. The secondary goal is to keep the library as lightweight as possible. 
What you're asking for is an edge case, not worth the added code weight. 

As I mentioned, the requested functionality is already possible without 
modifying the SWFObject library, and there are many different approaches that 
can be taken -- we don't want to assume one over another. 

If you don't like my suggestion, you're free to create your own -- SWFObject is 
available as open source on GitHub, feel free to make a fork.

Also, some 3rd-party libraries like CheckPlayer may contain the functionality 
you seek. http://checkplayer.flensed.com/index.php

Original comment by platelu...@gmail.com on 20 Sep 2011 at 5:08