0

I'm having troubles with my flyout. What happens with my gadget is you double click a component and it will have a corresponding flyout window. If you double click that or any other visual component with a flyout, though, the flyout document is returned as null. I have no idea why this is, and if you make the flyout go away and reopen it or a new one it's ok. It's only when a flyout is already opened this happens. I'm looking for some ideas on why this is.

Double click code:

Blah.prototype.ondblclick = function()
{

    var me = this.parent;

    if (System.Gadget.Flyout.show)
    {
        // flyout is already shown, make sure it shows our stuff
        System.Gadget.Flyout.file = FLYOUT_FILE;
        onFlyoutShow();
    }
    else
    {
        System.Gadget.Flyout.file = FLYOUT_FILE;
        System.Gadget.Flyout.onShow = onFlyoutShow;
        System.Gadget.Flyout.show = true;
    }
    System.Gadget.Flyout.onHide = onFlyoutHide;

    function onFlyoutShow()
    {
        me.flyoutOpen = true;
        me.updateFlyout();
    }

    function onFlyoutHide()
    {
        me.flyoutOpen = false;
    }
};

Executed code:

Blah.prototype.updateFlyout = function ()
{
    var flyoutDoc = System.Gadget.Flyout.document;
    //flyoutDoc is null at this point
    var info = flyoutDoc.getElementById("info");
    info.innerHTML = "info: " + this.information;
    //Error thrown: 'null' is null or not an object
}
user535617
  • 634
  • 2
  • 7
  • 22

1 Answers1

1

I don't know a lot about writing gadgets for windows 7, but to me it looks a lot like a timing issue. When the flyout is already there, you change the file property which tells it to load a new file. Without waiting you then call onFlyoutShow which tries to get the document and the document isn't loaded yet.

  • My first thought is: Doesn't the onShow event fire when you set the file? Probably doesn't or you wouldn't have the if, but worth verifying.
  • If that doesn't work, calling onFlyoutShow in a timeout. Start with a long timer, like 1000. And then shorten it, hopefully you can get down to 0: setTimeout(onFlyoutShow, 0);
Hemlock
  • 6,130
  • 1
  • 27
  • 37
  • Well, sir, you are correct about it being a timing issue, as the setTimeout fixed the problem. Now it's a matter of if I can do it the "right" way or not. For now, +1. – user535617 Jan 21 '11 at 21:26
  • I'm not convinced there is a right way. The documentation for System.Gadget.Flyout (http://msdn.microsoft.com/en-us/library/ms723669(v=vs.85).aspx) doesn't list anymore events. If you can set the timeout to 0, that is about as right as you can get it. – Hemlock Jan 21 '11 at 21:32
  • 1
    @user, @Hemlock: the best approach is to use a callback system. The code in the Gadget defines a function and when the JavaScript code in the flyout executes, it calls the function in the Gadget window so that it can do its business correctly. A timer might not be reliable, as factors can delay the timer from executing or delay the flyout from loading before the time executes. – Andy E Jan 26 '11 at 20:10