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)

Shares and Enjoy~

Did you like this post?

Subscribe here:  

29 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!

  15. birdwing Says:

    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.

  16. flashcrobat Says:

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

  17. Christian Says:

    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.

  18. Luke Says:

    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.

  19. Dave None Says:

    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.

  20. Robert Forsyth Says:

    Can the rotating images overlap in the Silverlight version, as they do in the Flash version?

  21. Dykam Says:

    The Silverlight animation works fluently on this Ubuntu machine where the Flash animation is a little laggy.

  22. wonderfulpackage Says:

    เก่งๆทั้งนั้น

  23. Moonlight, implementación libre para Silverlight « UbuntuWay – Generando conciencia! Says:

    [...] testear su funcionamiento en cualquier sitio web que use [...]

  24. skoti brendel Says:

    that’s still 2d the icon has no depth and i can’t rotate the icon in any direction
    that’s not 3d
    oh and by the way flash and silverlight both suck
    take it from me i created 3d windows in 98′
    long before looking glass

  25. 3D Image Rotation | Silverlike - A Free Microsoft Silverlight 3 Directory Says:

    [...] Demo New Window Website: http://www.shinedraw.com/3d-illusion/flash-and-silverlight-3d-image-rotation Download: [...]

  26. Amin Johar Says:

    Thanks for the script. I’ll try to use it :-)

  27. AlexG Says:

    Nice… works well on my Ubuntu Studio Linux install :)

  28. AC Says:

    Hi,Thanks for the sources.
    but how do i code it, if i want to open up a new windows when i click on a specific image

  29. Moonlight, o Silverlight do Linux — Espaço Liberdade Says:

    [...] http://www.shinedraw.com/3d-illusion/flash-and-silverlight-3d-image-rotation/ [...]

Leave a Reply