akihiko122 / swfobject

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

Callback-method on success or failure of embedding in dynamic publishing mode #126

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The old so.write() method in SWFObject 1.5 had a boolean return value,
indicating whether SWFObject was able to insert the swf into the page
content or not.

It would be nice to have this kind of feedback in swfobject 2 again. (Or
did I miss it in the documentation?)

If it's not possible to provide this directly via a return value, it would
be nice to be able to register a callback funtion, e.g. defined as a param:

var flashvars = {...};
var params = {
  ...
  callback: function(success) { alert("Successfully inserted swf: " +
success);}
};
var attributes = {...};
swfobject.embedSWF("myContent.swf", "myContent", "300", "120",
"9.0.0","expressInstall.swf", flashvars, params, attributes);

Original issue reported on code.google.com by johannes...@gmail.com on 14 Jul 2008 at 8:16

GoogleCodeExporter commented 9 years ago
SWFObject 2 works a bit different than SWFObject 1.5, because it uses 
unobtrusive
scripting instead of inline scripting, which means that now all non-DOM related
scripting is executed directly, while all DOM related stuff like SWF insertion 
will
execute in a deferred way. If you would like to know if your SWF will be 
inserted,
you can use swfobject.hasFlashPlayerVersion(versionStr) (zie API docu:
http://code.google.com/p/swfobject/wiki/api) to test for this.

We've had several requests for the addition of a callback function, to indicate 
that
your SWF has successfully been inserted into your Web page (basically to cross 
the
defferred 'gap', because hasFlashPlayerVersion will only indicate that it will 
be
inserted), so I think it is a useful feature for a future release.

Original comment by bobbyvandersluis on 14 Jul 2008 at 8:58

GoogleCodeExporter commented 9 years ago
Also I would like to stretch that, because SWFObject uses progressive 
enhancement (so
the basis is the most simple non-Flash version) and you can use 
hasFlashPlayerVersion
(directly fire JavaScript functions if failure), you only need a callback 
function in
case of success.  

Original comment by bobbyvandersluis on 14 Jul 2008 at 9:01

GoogleCodeExporter commented 9 years ago
I also agree it's a helpful feature for SWFObject... but just as an FYI, 
CheckPlayer 
(http://checkplayer.flensed.com/) has already implemented this an extension 
wrapper 
around SWFObject.  It provides dynamic publishing ability, with expressinstall, 
and 
plugin version check, and all three steps have callbacks which indicate success 
or 
failure.

The DoSWF() function (kind of like a cross between embedSWF and createSWF) has 
a 
callback which is notified either of failure or of success.  The success is 
reported 
in several stages, including INIT, PROGRESS (downloading), and COMPLETE.

In addition, a new version of CheckPlayer is about to be released (when the 
removeSWF issue with SWFObject is definitively addressed, either by my code or 
by 
swfobject) which will implement a fourth success state event which is "External 
Interface ready".

Just a thought, but perhaps instead of swfobject needing to re-invent that 
stuff, 
maybe CheckPlayer and SWFObject can be pointed to as co-operative efforts along 
these lines.

Original comment by get...@gmail.com on 14 Jul 2008 at 12:17

GoogleCodeExporter commented 9 years ago
Hi Kyle, we will look at what you've built for CheckPlayer. Just keep in mind 
that we
do not aim to build the most elaborate JavaScript API possible. A lot of people 
just
want a lean mean embedding machine, so to stay smaller than the 10Kb file size 
limit
is a very important goal for this project. But hey, if we can do it in a few 
bytes
and save authors a lot of hassle on functionality that will help a lot of 
people we will.

Original comment by bobbyvandersluis on 14 Jul 2008 at 3:23

GoogleCodeExporter commented 9 years ago
I agree, trying to keep things as small as possible is certainly an important 
goal. 
CheckPlayer is about the size of swfobject when uncompressed, so adding all 
it's 
functionality does kind of "double" a user's download size, but I believe 
there's a 
lot of helpful functionality it provides (like callbacks, and swf progress 
status 
events, etc). The way I try to "market" CheckPlayer is as an add-on to 
SWFObject. 
Certainly since it uses SWFObject it's not a replacement, but I think the API 
I've 
provided there can improve the author's usage of SWFObject in a decent amount 
of 
cases, not just small niche ones.

So, basically, my suggestion was just to say, if you don't want to put the 
callback 
functionality into SWFObject, or you feel that doing so to a full and proper 
degree 
would bloat SWFObject's core too much, maybe you could instead consider just 
recommending CheckPlayer to anyone who's looking for that kind of functionality.

The DoSWF() method is intentionally very similar in its API to the embedSWF 
function, and it's functionality tries to combine the best of both worlds from 
createSWF and embedSWF. So in that way, my goal was to make it a fairly easy 
bridge 
for SWFObject users to cross in the case where they needed something more than 
the 
core of SWFObject and didn't want to try and code it themselves.

I'm just trying to "play nice" with how I design and develop CheckPlayer, in 
that I 
think both our projects are helpful and should be as cooperative as possible to 
the 
benefit of the community.

Original comment by get...@gmail.com on 17 Jul 2008 at 2:09

GoogleCodeExporter commented 9 years ago
FYI, this EI_READY event has now been released for CheckPlayer (v0.7). It's 
available here:  http://checkplayer.flensed.com/

Original comment by get...@gmail.com on 19 Aug 2008 at 12:18

GoogleCodeExporter commented 9 years ago
You can check for success quite easily given how swfobject works at the mo - 
and if 
its only for layout issues you may not need any javscript!

if you ask swfobject to put the flash in '#main', and that is a div, swfobject 
wipes 
the div#main and replaces it with object#main.

This means for layout purposes you just target your CSS at one or the other. If 
you 
need something more complex then just inspect the DOM with javascript to see 
which 
is there.

-- Tim.

Original comment by Tim...@gmail.com on 25 Sep 2008 at 11:51

GoogleCodeExporter commented 9 years ago
Yes, it is quite possible to have each user roll their own CSS or javascript 
solutions for detection. I think the point of this topic/suggestion was 
debating if 
there was benefit in rolling some standard set of that into the core project 
(or, 
into extension projects, like CheckPlayer). The reason is that judging by the 
audience and traffic on the mailing lists, we get a lot of users of SWFObject 
that 
aren't as comfortable with their own coding, and just want to use something 
that's 
packaged simply and does everything they need.

It's easy to just tell someone "write some DOM inspection code, or use CSS to 
target 
the replaced element". But only a modest percentage of SWFObject's users are 
really 
comfortable or inclined to do so.

Original comment by get...@gmail.com on 25 Sep 2008 at 12:01

GoogleCodeExporter commented 9 years ago
For SWFObject 2.2 alpha8 we extended the API to also support a callback funtion 
to
indicate whether or not tyhe embed was successful:

swfobject.registerObject(objectIdStr, swfVersionStr, xiSwfUrlStr, callbackFn)
swfobject.embedSWF(swfUrlStr, replaceElemIdStr, widthStr, heightStr, 
swfVersionStr,
xiSwfUrlStr, flashvarsObj, parObj, attObj, callbackFn)

Where callbackFn is a JavaScript function that has an event object as a 
parameter:

function callbackFn(e) { ... }

Properties of this event object are:
- success, Boolean to indicate whether the embedding of a SWF was success or not
- objId, String indicating the ID of the object element
- altId, String indicating the ID of the alternative content (Dynamic 
Publishing only)
- objRef, HTML object element reference

e.g. using:

swfobject.embedSWF("test6.swf", "myContent", "300", "120", "9.0.0",
"expressInstall.swf", null, null, null, outputStatus);

or:
swfobject.registerObject("myId", "9.0.0", "expressInstall.swf", outputStatus);

with:
function outputStatus(e) {
    alert("e.success = " + e.success +"\ne.altId = "+ e.altId +"\ne.objId = "+
e.objId +"\ne.objRef = "+ e.objRef);
}

Additional test cases have been addedd to the 2.2 test suite:
http://www.bobbyvandersluis.com/swfobject/testsuite_2_2/

Original comment by bobbyvandersluis on 8 Dec 2008 at 2:30

GoogleCodeExporter commented 9 years ago
One loose end we will need to investigate:

The static publishing + browser communication example (mostly) returns null in
Firefox for the object element's reference. The getObjectById method somehow 
returns
null, because object.SetVariable is still undefined when the test takes place.

Original comment by bobbyvandersluis on 10 Dec 2008 at 9:35

GoogleCodeExporter commented 9 years ago
I build up a new SWFObject-File having Callback-Features.
The Site is german I know, but you can look at the code-part and all will be 
clear ;)

There is also a download-link. The Script was already compressed, if someone 
needs ne
source-code with whitespaces, please contact me.

http://derwebsider.de/2009/02/swfobject-mit-callback/

Original comment by mail.lor...@gmail.com on 10 Feb 2009 at 8:00

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
Using 2.2 ... I've passed a callback param to embedSWF(), but e.success is 
always 
true in the callback, even if I specify a completely bogus swf file name in the 
embedSWF() call.

Anyone know why?

Original comment by qazplmqa...@gmail.com on 23 Jun 2009 at 7:35

GoogleCodeExporter commented 9 years ago
AFAIK, that status is about whether or not the embed (insertion into the DOM) 
happened successfully. Not any validation on if the SWF has loaded properly.

For that, you might want to look at an extension library called CheckPlayer, 
which 
detects various more complicated events like that and lets you know when they 
occur.

Original comment by get...@gmail.com on 23 Jun 2009 at 7:44

GoogleCodeExporter commented 9 years ago
Using comment 9 it worked as a dream:
changed it to this:
function outputStatus(e) {
  if (!e.success) {
    location.replace("Url to load if no flash - like and iphone or a person form the past");
  }
}

tnx bobbyvandersluis :)

Original comment by ofktou...@gmail.com on 30 Aug 2010 at 2:22