Flash and Silverlight: 3D Text Space Flash and Silverlight: Mystery Magic Background
Aug 29

This is not a very impressive effect since there are dozen of free source codes for making the image rotation. However, it’s good to have a brief comparison on the differences of AS3 and C#. The samples created below are all re-organized for the ease of configuration and testing.

Comparison

Flash implementation: 1 hour
Silverlight Implementation: 1 hour
Blog Writing: 1 hours
Code Variation:

  • Children Sorting: setChildrenIndex [AS3] vs ZIndex Property [C#]
  • Loading images from library [AS3] vs Loading images from folder [C#]

Source Codes

Flash

Silverlight

Children Sorting: setChildrenIndex [AS3] vs ZIndex Property [C#]

Since AS3, children sorting is not as easy as just using swapDepths() [Due to the reason of speed enhancement]. It needs a little bit difficult approach for dealing this. Here is an example for sorting all the children in a specific container.

// AS3
// sort all the children according to their y position
sortChildren(container, "y");

// Sort the objects according to the image width
private function sortChildren(container : DisplayObjectContainer, cirteria:String) : void {

	var numChildren:int = container.numChildren;
	//no need to sort (zero or one child)
	if( numChildren < 2 ) return ;

	//create an Array to sort children
	var children:Array = new Array( numChildren );
	var i:int = -1;
	while( ++i < numChildren )
	{
		children[ i ] = container.getChildAt( i );
	}

	//sort by children by the criteria
	children.sortOn( cirteria, Array.NUMERIC );

	var child : DisplayObject;
	i = -1;
	while( ++i < numChildren )
	{
		child = DisplayObject( children[ i ] );
		//only set new depth if necessary
		if( i != container.getChildIndex( child ) )
		{
			//set their new position
			container.setChildIndex( child, i );
		}

	}
}		

However, in C#, it’s pretty straight forward now (Similar to the case in AS2).

// C#
// sort the children according to their y position
image.SetValue(Canvas.ZIndexProperty, (int) ((double) image.GetValue(Canvas.TopProperty)));

Loading images from library [AS3] vs Loading images from folder [C#]

In Flash 9, you can store all you images in FLA file and call them dynamically using AS3.

// AS3
// load the images from the FLA library
var imageClass : Class = ApplicationDomain.currentDomain.getDefinition("className") as Class;

// BitmapData needs 2 parameters, you may just set it to zero
// since it won't create any effect on it
var bitmapData : BitmapData = new imageClass(0,0);
var image : Bitmap = new Bitmap(bitmapData);
addChild(image);

While in C#, you may embed the image resources during compile time or load it dynamically from HTTP access. Just a reminder, if you want to get the width/height of the images, you have to get from the FrameworkElement property. (I have spent sometime searching this via the Internet)

// C#
// load the images from the Internet or from it's own resources
string url = "imageURL";
Image image = new Image();
image.Source = new BitmapImage(new Uri(url, UriKind.Relative));

// Get the image width after the image is successfully loaded
image.GetValue(FrameworkElement.ActualWidthProperty)

Random Posts

14 Responses to “Flash and Silverlight: 3D Image Rotation”

  1. Martin JANDA Says:

    As usual for MS software Silverlight doesn’t work on my linux machine :-). I would prefer flash to Silverlight. So if you can prefer Adobe solution to MS.

  2. admin Says:

    Hi Martin. Yup, may be Linux is still not working. (Or you also need Firefox 3 in Windows to make it work too)

    And actually I prefer Flash more. However, my objective here is try to demonstrate the differences of both of the technology.

  3. Indiabolbol Says:

    I think is a better choice because flash has been widely accepted and its supports both windows and non windows OS, even PDAs, Cell phones.

    –http://www.indiabolbol.com

  4. Link Post Sunday 08/31 | Mr Sun Studios Says:

    [...] Flash and Silverlight: 3D Image Rotation by Shine Draw [...]

  5. Ciaran Murphy Says:

    The Flash version renders off center if you navigate to another page and then return back. Entirely reproducable on IE. It renders in the top left hand corner. Just click on the comments section, allow it load and press the back button. Hey presto Flash is off center and SL is ok. Both are ok in Firefox, Opera &Safari.

  6. admin Says:

    Thx Ciaran Murphy for pointing out that. Are you using IE 6? There is a known bug for IE 6 to get the stageWidth and hence prodcued the error.

  7. Flash Tutorials | Flash and Silverlight Effect | Lemlinh.com Says:

    [...] Read more [...]

  8. Nicolaj S. Lindtner Says:

    But … silverligth do support languages that we allready spent years learning. Så if we please could use flash player with vb.net as developing language, this would be great. But probally not going to happen

  9. admin Says:

    Nicolaj, that’s really an interesting idea. But I agree with you that it’s not gonna happen. haha.

  10. Tony Says:

    Flash compiles to flash media format, at least microsoft is XML and can be inspected. I prefer SVG with VIDEO OGG support, but this doesn’t exist

  11. Proorsunsaday Says:

    Greetings, -wing recently a new browser from [url=http://www.google.com/chrome/index.html?hl=en&brand=CHMI&utm_source=ru-et&utm_medium=et&utm_campaign=ru]google.com[/url] who it include tried, how it to you? Whether there is a intelligibility to vibrating бета the construction? If who tried this origin, style please.
    ————————————————————————————————
    P.S. find if to that sector has written, the seek of administrators to cart a pole where you have regard for more proper :).
    P.P.S. On not which forums to me said, that this upshot A-one on some, that not so, here and has firm to learn from you.

  12. Subroto Says:

    think flash is very much easy and it is simple to implement in any kind of environment. flash is far ahead of silverlight.

  13. dotGicu Says:

    For .NET developers is much easier to implement, with silverlight.
    I believe that 1-2 ears silverlight will be much popular, and will support wide range platforms/browsers.

    - I observing flickering in flash version of this example, sl performs better.

  14. KurmanAhlabm Says:

    Hi there!
    My first post at this great blog!
    I wanna show u my dayly updated blog: Black Amateur Fuck Video
    Have a nice day!
    BB!

    P.S. if you don’t want to see this message please write me to no.ads08@gmail.com with subject “NO ADS” and URL of your forum
    Thank you for cooperation!

Leave a Reply