Silverlight Beta 2 Update Flash vs Silverlight: JavaScript Sample 1
Oct 23

This is a simple example demonstrating how to load an external image (not embed). It will also detect the downloading progress and illustrate it with the progress bar.

The source file size of Flash is much larger than Silverlight. It’s because I used many components in this application which result in a increase in file size.

Vote for this sample

Flash is Better! (331 votes)
Silverlight is Better? (300 votes)

Comparison

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

  • Loading Image: Loader [AS3] vs BitmapImage[C#]

Source codes

Flash

Silverlight

Loading Image: Loader [AS3] vs BitmapImage[C#]

The approach in detecting image loading progress in Flash is different to that of Silverlight. The image has to be loaded completely before you can add the image to stage.

// AS3
var urlRequest : URLRequest = new URLRequest(URL);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_complete);
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, on_progress);
loader.load(urlRequest);

private function on_complete(e : Event):void{
	// bitmap image
	var bitmap: Bitmap = loaderInfo.content as Bitmap;
}

private function on_progress(e:ProgressEvent):void{
	// e.bytesLoaded
	// e.bytesTotal
}

While in C#, you have to add the image to the stage for triggering the loading process. It seems that the you can’t detect the file size if you use BitmapImage to download the image.

// C#
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.DownloadProgress +=
	new EventHandler(bitmapImage_DownloadProgress);
bitmapImage.UriSource = new Uri(URL, UriKind.Absolute);
Image newImage = new Image() { Source = _bitmapImage };

void bitmapImage_DownloadProgress(object sender, DownloadProgressEventArgs e)
{
	int progress = e.Progress; // 0 = 100

	if (e.Progress == 100)
        {
		// finish
	}
}

Related Post

7 Responses to “Flash vs Silverlight: Loading External Image”

  1. unruledboy Says:

    I think sl is hiding the detail, since it can tell the progress, it definitely knows the size and current downloaded size, not simply not telling you(exposing it)

  2. Herberth Madrigal Says:

    Hi,

    I haven’t checked the code, but I only want to point out that browser usually caches the images. So , if you run first SL app, and after that you run FL app. The second application will load faster.
    On the other hand if you clear your cache, then your download speed might depend if any host between your computer and the source has cached the image, and also the ‘normal’ networking concepts (current bandwidth, the selected route, blah blah blah… )

    Regards,
    Herberth

  3. Nolz Says:

    You need to increas the FPS on the Flash-application to make the comparison more correct. this Flash-application is set to 12 FPS, who would set it to that?

    I like this concept, but you need to make the exampels more correct!

  4. rolf Says:

    too much cheap sharpening artifacts for silverlight, image looks better in flash… i vote flash then.

  5. Sphinx Says:

    Browser caching makes it hard to compare loading speed in the two examples. Silverlight seem to do a poor resampling job though - what rolf calls “cheap sharpening artifacts” is really not image sharpening but lack of real downsampling. I vote flash!

  6. haha Says:

    haha taaaaiiiiiizz de laid serieux ya trop rien ki marche

  7. tali Says:

    wats with the kid!!!

Leave a Reply