Silverlight vs Flash: Audio Player Pencake Ecard (Facebook Application)
Nov 05

I was pretty busy for the last week and that’s why I didn’t update here for several days.

In this application, there is an red ball bouncing between the Flash and Silverlight. The Flash is responsible to calculate the position of the ball. It will also pass the ball’s position the Silverlight application via JavaScript.

In the next sample, I will try to make the Silverlight as the master controller and demonstrate how to control Flash via JavaScript.

Comparison

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

  • ExternalInterface[AS3] vs RegisterScriptableObject[C#]

Source codes

Flash

Silverlight

ExternalInterface[AS3] vs RegisterScriptableObject[C#]

Firstly, we have to write a JavaScript to connect to the Silverlight and update it’s internal value. The JavaScript can be easily accessed by the Class ExternalInterface.

// JavaScript
function updateProperty( x, y ) {
	// JavaScriptSample2 is the Object Tag ID
	var silverlightObject = document.getElementById("JavaScriptSample2");
	if(silverlightObject.content != null)
		silverlightObject.content.JavaScriptSample2.UpdateProperty(x, y);
} 

// call the JavaScript inside AS3
ExternalInterface.call("updateProperty", ball.x, ball.y);

While in Silverlight, you have to register the class and method to the browser before they can be accessed outside the application. The registration is very simple.

// C#
// register the object to the client browser
HtmlPage.RegisterScriptableObject("JavaScriptSample2", this);

// make the method visible to the client browser
[ScriptableMember]
public void UpdateProperty(double x, double y)
{

}

Shares and Enjoy~

Did you like this post?

Subscribe here:  

26 Responses to “Flash vs Silverlight: JavaScript Sample 2”

  1. o UAU nosso de cada dia : Flash vs Silverlight: JavaScript Sample 2 Says:

    [...] aplicações conversam em tempo real: a bolinha vai e volta de flash pra Silverlight   Flash vs Silverlight: JavaScript Sample 2 Posted: Tuesday, November 04, 2008 8:26 PM by rene Filed under: silverlight, blog, [...]

  2. zdux Says:

    The biggest difference is that silverlight doesn’t work in my browser and a large percentage of broswers.
    Standards are important for a reason.
    We could jump on the MS bandwagon and leave users behind or we could use a technology that has stood the test of time.
    Perhaps there is some great advantage that is not in your example?

  3. egoZd Says:

    Let’s see!

  4. admin Says:

    the application runs properly in IE7, Firefox3 and Safari 3.

    That’s all I have tested.

  5. haagel Says:

    zdux: “Large procent of browsers”. Which browsers are you refering to?

  6. Bri Says:

    I have just tested this on Google Chrome, Safari (windows), Opera and Firefox and it works perfectly in all of them. I would therefore assume that the Mac Safari would work and isn’t there a linux silverlight plugin too?? That pretty much leaves Solaris and a few less common OSes so there is no problem running it. I figure that must cover 9/10 Desktop computers at least. Brilliant sample btw.

  7. Silverlight vs Flash Says:

    [...] Silverlight oder Flash? [...]

  8. w!ldc@t Says:

    I also tested this app in opera 9.62. It works!

  9. admin Says:

    hi all, thx for the testing resuls you have made!

  10. Daniel Says:

    Silverlight i definitly much easier to dev and perform better than flash. look at this site, you will find out how cool is silverlight. http://www.ecardoo.com

  11. birdwing Says:

    Daniel:

    There is nothing on that site that flash can’t do. although i don’t have an example ready to show you.

  12. spiggy Says:

    I am using Firefox 3.04 and find a very strange thing going on in some of these examples. In this example, instead of getting a working Silverlight area under the Flash area, I get a button that says Install Silverlight. But I already have Silverlight installed and it works in other examples of yours such as the passing query parameters example. In fact, on your browser integration page that has, I think, 3 examples, only the 1st one actually shows me a working Silverlight area. The other two show the “Install Silverlight” button. Strange. Maybe its 3.04 version of Firefox? Anyway, thought it might be useful info.

  13. alex Says:

    I not a dedicated microsoft person, for instance i always use firefoxall the time (which seems to work perfectly with silverlight, for me)

    Ive just started learning c# , asp.net. the site i need to create needs some significant graphical animations. so i took a look at silverlight, and started learning it, just in a few days ive been able to create stuff far beyond my expectations, with very little effort and knowledge of silverlight.

    not that i know much about flash development, but i do know about developing software, c# and vb.net are fast becoming one of the most popular languages to develop in.

    This means that even these developers will already be able to develop graphical applications with silverlight. I dont think most people would be bothered to try and learn another language just to develop some extra flash for there site. But as there are so many of these c# /vb.net programmers around already then youll start to see much more appearing.

    I think its very cleaver move by Microsoft. Expression Blend is also very nice and easy to use.

    I’ve always had the graphics ability of a monkey, but im totally sold on silverlight.

  14. Willem Says:

    It seems to me the animation in the Flash application is more constant. If you look closely to the Silverlight application and follow the ball closely you will notice a small hick up now and then.

  15. DruiDeGrey Says:

    Definitely for me as programmer much easier to work with Silverlight. But Silverlight allows design and programming to be separated for more complex vector graphics and animation.

  16. NewsPeeps Says:

    Flash vs Silverlight: JavaScript Sample 2…

    Thank you for submitting this cool story - Trackback from NewsPeeps…

  17. Meeting A New Pen Pal | Auctions Says:

    [...] and get more information on Pen Pal, you may find some inspiration on silverlight animation and silverlight sample Share and [...]

  18. How To seek A Pen Pal | Web Article Central Says:

    [...] get more information on Pen Pal, you may find some excitement on silverlight animation as well as silverlight sample Share and [...]

  19. Meeting A New Pen Pal | veryweblog focus on the internet ,new media. Says:

    [...] and get more information on Pen Pal, you may find a lot of inspiration on silverlight animation and silverlight sample Leave a [...]

  20. How To seek A Pen Pal | 247resourcecenter.com Says:

    [...] If you would like to promote and get more information on Pen Pal, you may find some inspiration on silverlight animation and silverlight sample [...]

  21. Meeting A New Pen Pal | veryweblog focus on the internet ,new media. Says:

    [...] more information on Pen Pal, you may find a lot of excitement on silverlight animation as well as silverlight sample Leave a [...]

  22. Getting A Foreign Pen Pal | Your-Home-Business.biz Says:

    [...] If you would love to support and get more information on Pen Pal, you may find a lot of excitement on silverlight animation as well as silverlight sample [...]

  23. Getting A Foreign Pen Pal | veryweblog focus on the internet ,new media. Says:

    [...] and get more reference on Pen Pal, you may find a lot of inspiration on silverlight animation and silverlight sample Leave a [...]

  24. Meeting A New Pen Pal | blabstr.com Says:

    [...] and get more information on Pen Pal, you may find some inspiration on silverlight animation and silverlight sample Share and [...]

  25. Global resort network How To seek A Pen Pal | global resort network Says:

    [...] If you would like to support and get more information on Pen Pal, you may find some excitement on silverlight animation as well as silverlight sample [...]

  26. recursos humanos peru Says:

    I must add that an important factor also is the objective of the project to be able to choose between one or the other technology.

Leave a Reply