Flash vs Silverlight: Flip Rotator Flash vs Silverlight: Image Carousel
Sep 18

Here we got the second application request (submitted by Maciek). He asked if it is possible to implement a general application which can show a mathematical equation like y = x^3 + x^2 + 2 + 5. I think this is a very difficult topic and what I have done is to illustrate the idea by a simple example. Hope this application will give you some inspirations.

In this sample, the red dot is constantly moving fore and back. The y position is determined  by an internal function locusFunction. However, the locusFunction is a function pointer only and it points to some functions defined by me. In the Silverlight, I have implemented 4 different locus function. You may also use this framework to implement your own locus easily.

Comparison

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

  • Passing Function as parameter: var functionPointer:Function [AS3] vs delegate void functionPointer() [C#]

Source codes

Flash

Silverlight

Passing Function as parameter: var functionPointer:Function [AS3] vs delegate void functionPointer() [C#]

Since AS3 is a weak function, using function pointer is easily since you don’t need to care about the return type and the number of parameters. But of course, it makes debug much more difficult.

Well, I think weak language is one of the major factory that makes Flash so popular. Through the code may be insecure, but at least you can achieve the result easily.

// AS3
var functionPointer:Function;

function flash(version:String):void{
	trace(version);
}

function silverlight():String{
	return "beta 2";
}

// trace "cs3"
functionPointer = flash;
functionPointer("cs3");

// trace "beta 2"
functionPointer = silverlight
trace(silverlight());

While in C#, it’s completely another story. You need to create a delegate type first and everything must be matched. It’s really a bit complicated, let’s take a look at the sample below.

// C#
delegate void newType(string version);
newType functionPointer;

void flash(string version){
	System.Console.WriteLine(version);
}

string silverlight(){
	return "beta 2";
}

// output "cs3"
functionPointer = flash;
functionPointer("cs3");

// you will get an error for this
functionPointer = silverlight;

// try to do it in this way
delegate string anotherType();
anotherType newPointer;
newPointer = silverlight;
System.Console.WriteLine(newPointer());

Shares and Enjoy~

Did you like this post?

Subscribe here:  

8 Responses to “Silverlight vs Flash: Mathematical Locus”

  1. Kowd Says:

    The silverlight delegate definition may look a bit cumbersome but that is why you have the Action and Func generic delegates. Also anonymous delegates and type inference is cool:

    //Type inference: + Func
    var wow = new Func(silverlight);

    //Simple function defined in a single row:
    Action wow2 = p => Console.WriteLine(p);

    With the generic delegates you rarely need to create your own delegates unless they are part of a library or a framework (where a more descriptive name is needed).

  2. unruledboy Says:

    it seems that sl is slower than fl :)

  3. admin Says:

    Yes, Silverlight seems slower.

    I am going to implment the FPS counter to give the reader more idea how they are performing.

  4. muffin Says:

    Out of curiosity do you know what proportion of visitors to this page have flash installed vs silverlight?

  5. Silverlight Cream for September 18, 2008 -- #372 Says:

    [...] Silverlight vs Flash: Mathematical Locus [...]

  6. Flash ve Silverlight karşılaştırması | AdobeHaber Says:

    [...] Flash Silverlight Download [...]

  7. Kathryne Randrup Says:

    This is a very interesting post, I was looking for this knowledge. Just so you know I located your site when I was looking around for blogs like mine, so please check out my site sometime and leave me a comment to let me know what you think.

  8. blemish solution Says:

    I’ve been searching good information about this subject for some time and I gotta say you put up provides me some normal idea about my paper I am gonna write for my assignment. I would like copy some of your words right here and I hope you do not mind. Thanks. I’ll reference your work of course. Thank you.Maintain updating the good posts. will come back.

Leave a Reply