As Kyle mentions, sometimes you just have to wait.  The ExternalInterface
mechanism is not available immediately upon loading the SWF... it takes a
few (milli)seconds.  If you try to access EI before it has fully loaded,
you'll get an error.  The simple solution is to ping the SWF until EI is
ready... I believe this is what Kyle's system CheckPlayer system does.

- philip


On Fri, Jan 30, 2009 at 4:50 AM, Getify Solutions, Inc. <get...@gmail.com>wrote:

>
> Also, to chime in, there are in fact sometimes timing problems (in various
> browser/embedding environments) with accessing a SWF (even in the ONLOAD
> event handler) and trying to access it's ExternalInterface functions.
>  There
> are a few "recent" threads about that topic.
>
> I have a helper library called CheckPlayer (
> http://checkplayer.flensed.com/)
> which implements a set of logic to "wait and check for" EI availability,
> and
> then when it's definitively ready, it calls a function of your choice (your
> "callback") to let your code know.
>
> So, either using that library, or implementing your own logic similar to
> that, is the key... you have to "asynchronously" wait for the EI to become
> ready (after the call to embedSWF) before you are able to make calls to it
> (especially if embedSWF is called during loading of the page before dom is
> ready!).
>
> --Kyle
>
>
>
>
>
> --------------------------------------------------
> From: "Aran Rhee" <aran.r...@gmail.com>
> Sent: Friday, January 30, 2009 3:31 AM
> To: <swfobject@googlegroups.com>
> Subject: RE: Trying to access the flash element right after
> swfobject.embedSWF  results in error
>
> >
> > Embedding / ID - so when the swf gets written to the page, it will
> > overwrite
> > the old div etc and take over the ID. You the notes are correct, you are
> > grabbing the ID of the swf (which WAS the ID of the replacement element)
> >
> > callEI() - This was just an example function name to demonstrate that you
> > could call whatever function you wanted to on the onload event :)
> >
> >
> >
> > Cheers,
> > Aran
> >
> >
> >
> >
> > -----Original Message-----
> > From: swfobject@googlegroups.com [mailto:swfobj...@googlegroups.com] On
> > Behalf Of Mohan
> > Sent: Friday, 30 January 2009 6:30 PM
> > To: SWFObject
> > Subject: Re: Trying to access the flash element right after
> > swfobject.embedSWF results in error
> >
> >
> >
> >
> > On Jan 30, 1:51 pm, "Aran Rhee" <aran.r...@gmail.com> wrote:
> >> First of all, just checking - Did you overwrite the id with something
> > other
> >> than "flashcontent" in your attributes object? If not, then you want:
> >>
> >> var swf = document.getElementById("flashcontent");
> >
> > Hmm. Thats different from what I have seemed to understand from  the
> > ""Dynamic publishing" section of the tutorial at
> > http://www.pipwerks.com/lab/swfobject/ExternalInterface/2.0/index.html.
> > In the "Notes" it indicates that you grab hold of the SWF by using its
> > ID and not the id of the element that you pass in the call to
> > swfobject.embedSWF. Am I reading that wrong ?  The working example at
> > http://www.pipwerks.com/lab/swfobject/ExternalInterface/2.0/dynamic.html
> > also uses the SWF ID and that seems to work ok, so I think this is
> > correct, no ?
> >
> >> Also - have you looked at the reference page examples for external
> >>
> > interface:
> http://www.bobbyvandersluis.com/swfobject/testsuite_2_1/test_dynam
> > ic_...
> >
> > Sorry mate - I am getting a 404 when clicking the link you gave
> > above?
> >
> >> l
> >>
> >> I think you want to try to call the EI method only once you have an
> >> onload
> >> event on the window / page to ensure everything is ready and available,
> >> so
> >> you could do something like:
> >>
> >> <body onload="callEI();">
> >
> > Where can I find more information on this callEl  function ?
> >
> >>
> >> On write a separate onload function within your <head> functions like:
> >>
> >> window.onload = function()
> >> {
> >> var swf= document.getElementById("ExternalInterfaceExample");
> >> if (swf && typeof swf.sendTextToFlash != "undefined")
> >> {
> >> swf.sendTextToFlash(text);
> >> }
> >>
> >> }
> >>
> >> Philip (pipwerks) or others may have a better solution than this...
> >
> > Thanks for the suggestions mate.
> >
> >
> >>
> >> Aran
> >>
> >> -----Original Message-----
> >> From: swfobject@googlegroups.com [mailto:swfobj...@googlegroups.com] On
> >>
> >> Behalf Of Mohan
> >> Sent: Friday, 30 January 2009 4:13 PM
> >> To: SWFObject
> >> Subject: Trying to access the flash element right after
> >> swfobject.embedSWF
> >> results in error
> >>
> >> Hello,
> >>
> >> I have been trying to use this great library to embed some flash
> >> dynamicly and then access the flash API via javascript
> >> (ExternalInterface). The problem I am having seems to be, because I
> >> try to access the flash element right after the call to
> >> swfobject.embedSWF, the element does not seem to be ready yet.
> >>
> >> For example, starting with the example code
> > fromhttp://
> www.pipwerks.com/lab/swfobject/ExternalInterface/2.0/dynamic.html
> >> (Thanks for the example!), if I were to modify the following
> >> javascript in the dynamic.html global scope by trying to get at the
> >> swf object I get an "swf is null". However the event handling code
> >> that access the flash element still works ok, indicating that the
> >> flash did get embedded ok.
> >>
> >> swfobject.embedSWF("ExternalInterfaceExample.swf", "flashcontent",
> >> "550", "200", "8", false, flashvars, params, attributes);
> >> var swf = document.getElementById("ExternalInterfaceExample"); //added
> >> line
> >> swf.sendTextToFlash(text); //trying to use the flash object right
> >> after embedding it
> >>
> >> Is this because the flash element is not ready yet ? How would I
> >> implement something that needs to be run right after the call to
> >> swfobject.embedSWF ? The examples I have seen always make use of the
> >> swfobject in some event handler and not right after the call to
> >> swfobject.embedSWF. Any help would be greatly appreciated.
> >>
> >> Mohan
> >
> >
> >
> > >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SWFObject" group.
To post to this group, send email to swfobject@googlegroups.com
To unsubscribe from this group, send email to 
swfobject+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/swfobject?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to