Tags: | Posted by Admin on 8/23/2007 4:06 AM | Comments (0)

Everyone knows Silverlight is an object embedded in the browser.  Therefore, it has the same nuances as other plugins like Flash.

What nuances?  Good question.

Nuance #1 - Displaying HTML over Silverlight

I added an autocomplete extender to the airport name text box at www.airportwait.com.  It worked great, except that the dropdown selections don't display over the Silverlight control on the page.  This has always been an issue with plugins, and even with select controls (thankfully, the select control issue is fixed in IE7). 

To fix it, I redesigned the page to hide the Silverlight control during airport name entry.

Nuance #2 - Silverlight object timing issues

I have a javascript method called ProcessResults that calls a method on my Silverlight object, which in turn displays the airport wait times.  I tried this:

createSilverlight();
ProcessResults();

No good. There's a certain amount of time after createSilverlight() is called when the object isn't yet available. 

So, I had to do this:

createSilverlight();
StartResultsDisplay();

function StartResultsDisplay()
{
    setTimeout("ProcessResults()", 500);
}

function ProcessResults()
{
...
}

This way, I wait half a second before beginning to display the data.  Problem solved.

Oops.  As soon as I wrote this, I remembered I could just specify an onLoad event handler for the Silverlight plugin.  I thought about deleting this part, but it's still good info if someone else is dealing with the same thing.

Silverlight.createObjectEx({
...
    },
    events: {onLoad:ProcessResults}
});

UPDATE: I changed this again.  Because the Silverlight control was immediately calling the ProcessResults method after loading, the page didn't render fully until the loading was complete.  This is because it takes a second or two to retrieve data for some airports, and during this time Silverlight "hangs" browser events. 

Now, I still use the Silverlight onload event handler, but I wait a quarter-second to give the browser time to finish rendering.

events: {onLoad:function() {setTimeout("ProcessResults()", 250)}}

Summary

Again, these aren't uncommon issues.  Still, they're the types of things that just continue to remind me that, while I love the deployment model and reach of the web, it will always be inelegant compared to smart client development!