Aug 03

I have uploaded 40 of my Shine Draw samples into the Silverlight Resources Directory. There are many new features, go and check it out now! You may also upload you own resources. Later on, I will write an article on teaching users how to use it.

New Features

  1. Integrated with the Frame Control. The navigation is very easy!
  2. Optimized for SEO. (I hope the search engine will sooner or later index all of the pages)
  3. Counter the number of view of each resources
  4. User is able to submit their own resources
  5. Out of browser

 image

Remarks

You may find that when you load the Home Page, it will take a while to load. It’s because every the page is loaded, it will download data from the server again. I will try to save the data into the load storage later on to speed up the navigation.
I used Isolated Storage to store the data, the navigation will be much faster now. I will further optmize the loading speed later on.

Jun 16

You can use this application to share photos that stored in your server with your friends easily. You may now download it to play. Source code is available upon purchase. Only USD $10! 

Online Demo

Click here

Download Application

You may download the Silverlight Application via the link below:

download  Silverlight Photo Explorer 1.0 (77.8 KiB, 1,583 hits)

Features:

  1. Integrate with PHP to display server side folder structure and image files.
  2. On demand folder listing which enhance your browsing experience.
  3. Thumbnail generators which speed up your loading speed.
  4. Customizable layout and style.

Screenshots:

image

Dec 17

Loading external libraries is a very effective method to minimize the application file size. Through it’s useful, I found that it’s seldom discussed in the Internet.

I learned this a few days ago and I think that it’s important to share it immediately to al of you.

In the sample below, I have implemented a host application where it will download the assembly made from my sample “Simple Game System“. Once the assembly is downloaded, the application can initialize a a specific class from the assembly.

Comparison

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

  • LoaderContext [AS3] vs AssemblyPart [C#]

Source codes

Flash

Silverlight

LoaderContext [AS3] vs AssemblyPart [C#]

In Flash, there is no dll file. However, once a SWF file is complied, you can actually utilize the resources inside the swf file. Here is a simple demonstration.

// AS3
var _assembly:Loader = new Loader();
var _loaderContext:LoaderContext = new LoaderContext();

// download the swf file
function download():void{
	var request : URLRequest = new URLRequest( SWF_PATH);
	_assembly.contentLoaderInfo.addEventListener(Event.COMPLETE, on_download_completed);
	_assembly.load(request, _loaderContext);
}

// create an instance from the resources
function on_download_completed(e:Event):void{
	var className : Class = _loaderContext.applicationDomain.getDefinition(CLASS_NAME) as Class;
	var displayObject : DisplayObject = new className();
	addChild(displayObject);
}

The approach in Silverlight is different. We are not going to download xap file as the assembly. Instead, will need to use the dll file generated form a project as the assembly resources.

// C#
WebClient downloader = new WebClient();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(onDownloadCompleted);
downloader.OpenReadAsync(new Uri(DLL_PATH, UriKind.Absolute));

// Once the assembly is downloaded
private void onDownloadCompleted(object o, OpenReadCompletedEventArgs args)
{
    try
    {
        AssemblyPart ap = new AssemblyPart();
        Assembly assembly = ap.Load(args.Result);
	UserControl control = (UserControl) _assembly.CreateInstance(CLASS_NAME);
	LayoutRoot.Children.Add(control);
    }
    catch (Exception e){}
}
Dec 01

Sometimes, your application may need to save the user state or progress for various purposes. Rather than storing the information to server, both technology provided a very convenient way to store some temporary data into user computer.

However, the storage has it own limit size for security reason.

Comparison

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

  • flash.net.SharedObject [AS3] vs System.IO.IsolatedStorage.IsolatedStorageFile [C#]

Default local storage limit

  • Flash: 100 KB (Can be adjusted to unlimited by user)
  • Silverlight: 1024 KB

Source codes

Flash

Silverlight

flash.net.SharedObject [AS3] vs System.IO.IsolatedStorage.IsolatedStorageFile [C#]

Using Local Storage is pretty easy in Flash. It’s because you only have to deal with the shared data as if local Object.

Please note that you have to call the flush() method after updating the object. Just to make sure it is saved into file system.

// AS3
// get the shared object
var so: SharedObject = SharedObject.getLocal(OBJECT_NAME);

// load data from local storage
if(so.data.text){
	TextArea.text = so.data.text;
}

// save data to local storage
so.data.text = "New Text";
so.data.flush();

In Silverlight, the local storage is actually a predefined path of storage directory. You can read and save data as if reading and writing files.

// C#
// load data from local storage
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if(store.FileExists(FILENAME)){
	isfs = new IsolatedStorageFileStream(FILENAME, FileMode.OpenOrCreate, store);
	StreamReader streamReader = new StreamReader(isfs);
        string s;
	while ((s = streamReader.ReadLine()) != null)
		TextArea.Text += (s + '\n');
	streamReader.Close();
}

// save data to local storage
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(FILENAME, FileMode.OpenOrCreate, store);
StreamWriter streamWriter = new StreamWriter(isfs);
streamWriter.Write("New Text");
streamWriter.Flush();
streamWriter.Close();
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.

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
	}
}