Flash vs Silverlight: Loading External Image Silverlight vs Flash: Throwing Object
Oct 24

When talking about Silverlight and Flash, one should not miss out the browser integration part.

The sample below demonstrate three basic browser integration techniques: open popup, modify CSS and amend HTML content.

This is the first sample only. I will try to come up the 2th, 3th, 4th.. 10th samples later on.

Comparison

Flash implementation: 30 minutes (Implemented First)
Silverlight implementation: 40 minutes
What’s the difference?

  • Browser Integration: navigateToURL [AS3] vs HtmlPage [C#]

Source codes

Flash

Silverlight

Browser Integration: navigateToURL [AS3] vs HtmlPage [C#]

I think you can do whatever you want in Flash. It’s because you can write JavasScript directly in AS3.

// AS3
// open popup
var js:String = "window.open('URL','_blank','height=300,width=300');";
var url : URLRequest = new URLRequest("javascript:" + js+ " void(0);");
navigateToURL(url, "_self");

// modify CSS
var js:String = "document.body.style.backgroundColor='#FF0000';"; 

// amend HTML content
var js:String = "document.getElementsByTagName('h1')[0].innerText = ‘Value’;”;

Silverlight provided a set of API to manage the HTML DOM. However, I am not sure if you can call your own JavaScript directly as in Flash.

// C#
// open Popup
HtmlPage.PopupWindow(new Uri("URL", UriKind.Absolute)
	, "_blank",
	new HtmlPopupWindowOptions() { Width = 300, Height = 300});

// modify CSS
HtmlDocument document = HtmlPage.Document;
document.Body.SetStyleAttribute("background", "#0080FF");

// amend HTML content
HtmlDocument document = HtmlPage.Document;
ScriptObjectCollection collections =  document.GetElementsByTagName("h1");
HtmlElement htmlElement = (HtmlElement) collections[0];
htmlElement.SetProperty(”innerHtml”, “This is Silverlight Title”);

Shares and Enjoy~

Did you like this post?

Subscribe here:  

8 Responses to “Flash vs Silverlight: JavaScript Sample 1”

  1. Mina Saad Says:

    The popup window doesn’t appear in both cases in FireFox but opens a new tab , is a way around this ? , off coarse I can change from FireFox options but I ask if I can force it !!!!!

    Thanks

  2. TomC Says:

    I think you can call your own JavaScript in Silverlight using the following method:
    HtmlPage.Window.Eval()

  3. Shahzad Says:

    Yes, you can call javascript directly from Silverlight.

    Silverlight is clientside like javascript, so just think of all that silverlight code hiding in a silverlight box on the page, it’s right next door to any javascript on the same page.

  4. admin Says:

    Mina Saad, I think most of the browsers will either block the pop up or open in a new tab.
    There should be no way to force Firefox to do it, but I think you may change the Firefox settings and make it works only.

    TomC, thanks for the suggestion, I will try to use it next time~

  5. ramoson Says:

    ı dont believe you .
    why do you make silverlight first?
    ı think you take money from microsoft.
    silverlight is new is cheep.ı dont believe it’s advanced about in scripts and programming

  6. Bart Czernicki Says:

    Looks like the Flash/Flex version has a bug in it. If you click one of the buttons and release the buttons fly around and go crazy. In the Silverlight version it looks to work fine.

  7. Mino Says:

    In Mac osx, with safari Open Popup and Change Title do not work.

  8. ramoson Says:

    its up to you.if your programming capacitie good you can fine button and more whats.

Leave a Reply