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
3D Image Rotation [Flash 9, AS3] (112.5 KiB, 3,277 hits)
3D Image Rotation [Silverlight 2, C#] (249.3 KiB, 18,455 hits)
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)
August 29th, 2008 at 12:45 pm
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.
August 29th, 2008 at 3:40 pm
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.
August 30th, 2008 at 12:20 am
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
September 1st, 2008 at 12:03 am
[...] Flash and Silverlight: 3D Image Rotation by Shine Draw [...]
September 1st, 2008 at 11:10 pm
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.
September 2nd, 2008 at 12:56 am
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.
September 4th, 2008 at 12:38 am
[...] Read more [...]
September 11th, 2008 at 10:20 pm
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
September 11th, 2008 at 11:24 pm
Nicolaj, that’s really an interesting idea. But I agree with you that it’s not gonna happen. haha.
September 15th, 2008 at 11:35 pm
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
October 8th, 2008 at 10:40 pm
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.
November 4th, 2008 at 4:32 pm
think flash is very much easy and it is simple to implement in any kind of environment. flash is far ahead of silverlight.
November 5th, 2008 at 11:45 pm
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.
November 8th, 2008 at 3:16 pm
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!
November 19th, 2008 at 9:36 am
I personally don’t see anything special about silverlight.
If your only argument is that you can use C# instead of using Action Script than you need to stop whining. AS is very easy to learn, and it shares elements of C# its not exactly the same, but its close enough to pick up with little hassle.
Personally, microsoft has a habit of dropping cross platform compatability when they gain the majority market share, and that’s bad news for us Mac users.
Flash can do everything silverlight can I see no benefits or disadvantages this is just Microsoft trying to but into another part of the Technology marketplace.
January 9th, 2009 at 10:29 pm
cheers for explaining “Loading images from library [AS3] vs Loading images from folder [C#]”
I had completely forgotten how to load an image from the library directly, and amazingly was not easy to find smthgn quickly in googlegod. I will post a reference to your blog on mine..
March 6th, 2009 at 7:44 pm
Right now, both examples are quite nice. It’s amaizing that there is not big difference at all. Therefore, SL will grow in popularity, because it will be implemented by large companies in their software products. I am sure it will, very soon, be introduce to other platforms as well. C# has a bigger bonus in .net frameworks, being able to make serverside image modification to the level of a bit.
March 9th, 2009 at 8:35 pm
Silverlight was invented as part of WPF which is a replacement for the old GDI+ way to write UIs. Windows programmers have never had a rich toolset for this, going beyond the basic UI listboxes and treeviews in Windows was beyond the reach of the vast majority of Win32 devs. Silverlight is a port of WPF for cross platform browser compatibility and forms a vital part of the MS internet strategy in that the future OS is a browser, and MS aren’t going to make MS Word available in the cloud by using Flash when they have WPF. Flash and Silverlight will live together as tools for use depending upon many factors. Its not a “Flash killer” as the online tabloids put it, its just a solution to a need in the MS product lineage.
April 29th, 2009 at 3:28 pm
Silverlight is the next generation technology. Soon, you wont remember what flash was, nor javascript. Silverlight is incredible and finally bridges the gap between design and code. So many people shun it because they dont understand it.
The problem with other technologies, like flash for example, is it came out, people liked it, people use it, but it has not future road map. It has no direction.
Silverlight has a road map and destination.
May 13th, 2009 at 5:47 pm
Can the rotating images overlap in the Silverlight version, as they do in the Flash version?
June 10th, 2009 at 2:08 am
The Silverlight animation works fluently on this Ubuntu machine where the Flash animation is a little laggy.
June 27th, 2009 at 2:20 am
เก่งๆทั้งนั้น