External Interface error: Object expected

It’s taken me a while to figure this one out. I have a flash game on facebook that uses Stage3D, so window mode has to be set to “direct” which means that any time facebook wants to overlay some elements on the page they appear under the game on many browsers.

Facebook has a solution for you, on FB.init you can set your own callback function via the hideFlashCallback parameter. In this callback you can move the flash object out of view by, for example, setting the top to be -10000px whenever a Facebook dialog is opened and then putting it back when the dialog is closed.

I had functions registered with external interface to pause and resume the game that would get called via javascript in the hideFlashCallback callback.

This was working well enough but for some reason on Internet Explorer I couldn’t call the resume() function just after showing the flash object, instead I got an “Object Expected” error.

Internet Explorer does not support calling external interface methods for flash objects if they are not visible. Since it could be a race condition (DOM might not render the flash object before the function was called) I added a 100ms delay to the call to resume(), only for IE. This seemed to work fine.

But once we got close to production this error re-appeared, but only when Facebook’s purchase dialog had been shown. Weird! No amount of delay made the external interface calls work again. If I showed the purchase dialog once and closed it, it would be no longer possible to call any external interface functions for the flash object until a page refresh. This was not acceptable.

After a lot of debugging, I noticed that even though we have registered for the hideFlashCallback function, facebook STILL sets the visibility of the flash object to “hidden” after 200ms.

As can be seen in Facebook’s documentation: “The custom action must complete within 200ms or the Flash object will be hidden automatically regardless.”

Apparently the fact that we’re changing the visibility of the flash object along with whatever facebook does differently during the purchase dialog (overlay a white div over the whole page) breaks all external interface functionality.

This has a simple fix though, create a higher priority CSS rule that makes the flash object always visible:

It doesn’t need to be hidden since we are moving it out of view ourselves anyways.

Tags: , , , , , , , , ,

16 Responses to “External Interface error: Object expected”

  1. Brice & Antoine Says:

    This is EXACTLY the description of our bug !
    Thanks for the fix.

    You rock !

  2. Flassari Says:

    So glad that I could help someone out with this =)

  3. Brandon Says:

    I have this exact problem, however this fix isn’t working for some reason. Is it possible to get a copy of the javascript source, for setting the flash object to visibility: visible !important;

  4. Brandon Says:

    I actually think my problem is different as even if I don’t have any external interface methods I get a problem with losing the flash object.

    I use the following FB.Init……………..

    FB.init({
    appId : ‘MY_APP_ID’,
    hideFlashCallback : onFlashHide
    });

    even when I make the callback function onFlashHide do nothing… the flash object is still lost when someone PMs and I close their PM box.

    I notice that the flash object is still present, as if I right mouse click on the area it brings up the flash menu, it just isn’t drawing / rendering for some reason.

  5. Brandon Says:

    I got this fixed.. I wasn’t using the correct Flash Object ID for the CSS Code. Once I used the correct Object ID, everything worked fine. Thank you for the following code :)

    #MyFlashObjectID {

    visibility: visible !important;

    }

  6. Bach Le Says:

    I am eternally indebted to you. Thank you very much for sharing your fix.

  7. Philip Says:

    great fyi… mental note created – thanks! :)

  8. ahh Says:

    Youre my hero. Oh my god. After 5 hours of debugging!

  9. DFreeman Says:

    Oh God, THANK YOU!
    I’ve spent a week on this problem. From thinking it was facebook javascript api, to swfobject to just IE8, I’ve read hundreds of pages with proposed solutions and you are the only person with not only the EXACT problem but a solution!!!
    /internet hug

  10. PC Says:

    Exactly what I was looking for! Thanks!

  11. khris Says:

    OMG, I love you and your article even than double cheese burger.

  12. Marek Says:

    You saved me a day! Thx a lot.

  13. Fahim Says:

    I’ve got the same issue, I’ve implemented the whole fb take image thing and it’s working perfectly fine. The issue is thought the callback function is never called. I’ve got an alert there but it’s never called (chrome)

    If I remove the function from FB.init my game disappear when I click on notifications but when I put in the function. The function isn’t called and nothing happens.

    Any clues?

  14. Jakob Says:

    For those who do not understand what he meant by creating a high priority css rule and need an example, here you go:
    His suggestion-
    #MyFlashObjectID {
    visibility: visible !important;
    }

    My interpretation-
    head
    style type=”text/css”
    /*below is where you place the visibility code*/
    #flashContent {
    visibility: visible !important;
    }
    /style
    /head
    /*sorry it wouldn’t let me add a lot of detail on this*/

    I hope this helps those who may still be lost.

  15. Ami Says:

    amazing. this was the save of the month :)
    spot on!

  16. luis Says:

    You save me THANKS!!!!!!!!!