Double Sided Plane in Flash Player 10

So I just returned from a two month “cruise” (Navy term for “hell on a ship”) to Europe and back to the states (survived the Bermuda Triangle incidentally) last night and I suddenly find out two things: our cat, Hildegard, has a brand new kitty home back in Ireland and Flash 10 beta is available for download and testing.

Well, awhile back, I showed a fairly simple way to make a double sided plane using Papervision3d. Since Flash 10 supports basic 3d natively (!), I thought I’d do something similar for my first F10 experiment. The first thing you’ll notice that’ll annoy the snot out of you when playing with 3d in Flash is how z sorting is handled. Flash’s display index position will “always” (I use quotes as I very well could have overlooked something) override the 3d DisplayObject z property. Which is to say, if I add displayObject1 to the stage, then add displayObject2, with the same dimensions as the first, to the stage at the same coordinates, but set number 2′s z property to 1000 (e.g.), displayObject2 will appear much smaller, but will still appear on top of displayObject1. Ick. Hopefully that will be fixed in the final release. Obviously something farther away should appear behind something closer, regardless of the order they entered the display list. For this reason, the “push one side of the plane back 1 pixel” trick I used in the PV3d version will not work here. Instead I had to use a bit of a “hacky” work around and hide the back side of the plane using the visible property when it shouldn’t be seen. Anyway, here’s the down and dirty class file that does the work:

package {
 
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.DropShadowFilter;
 
	/**
	* Double sided plane in Flash 10
	* @author Devon O.
	*/
	[SWF(width="500", height="400", backgroundColor="#333333", framerate="31")]
	public class main extends Sprite {
 
		[Embed (source="assets/face.jpg")]
		private var Face:Class;
 
		[Embed (source="assets/back.jpg")]
		private var Back:Class;
 
		private var card:Sprite;
		private var faceImage:DisplayObject;
		private var backImage:DisplayObject;
 
		public function main() {
			initImages();
			initCard();
 
			addEventListener(Event.ENTER_FRAME, frameHandler);
		}
 
		// create new images for "face" and "back" of card using embedded jpg files
		private function initImages():void {
			faceImage = new Face();
			faceImage.x -= faceImage.width * .5;
			faceImage.y -= faceImage.height * .5;
 
			backImage = new Back();
			backImage.scaleX = -1;
			backImage.x = -faceImage.x;
			backImage.y = faceImage.y;
			// push the back image a little into z space
			backImage.z = 1;
		}
 
		private function initCard():void {
			card = new Sprite();
			card.x = 250;
			card.y = 200;
			card.rotationZ = -15;
			card.addChild(faceImage);
			card.addChild(backImage);
 
			card.filters = [ new DropShadowFilter(50, 45, 0x000000, .75, 16, 16, 1, 2) ];
 
			addChild(card);
		}
 
		private function frameHandler(e:Event):void {
			card.rotationY -= 10;
			var currentRot:Number = -(card.rotationY % 360);
			// hide the back image when the face should be in front
			backImage.visible = (currentRot > 94 && currentRot < 274);
		}	
	}
}

And that will yield (of course you will need the Flash Player 10 installed to see):

More Flash 10 goodness yet to come…

4 Comments

  1. Acts7 says:

    Thats incredible. The best part is no jagged edges with the rotated image.

  2. Devon O. says:

    Thanks, Acts7.. I was surpised too. I expected to have to use BitmapData to do some smoothing, but nothing doing.. Pretty amazing..

TrackBack URI

Sorry, the comment form is closed at this time.

Devon O. Wolfgang

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development”

Contributing Author of “Flash AS3 for Interactive Agencies”

Senior Software Developer in Dublin, Ireland

Portfolio

Bayer Pixel Bender Filter

Bayer Mosaic Filter in Pixel Bender


Now, seeing as how I’ve been trying to learn some Pixel Bender coding lately[...]

Liquitext

Liquid Text Effect


Haven’t been too active around here lately due to a major on going project at work lately as well as the fact that my wife and I are in the slow process of moving homes. Really, the only free time it seems I have these days is during the lunch hour. So, over the past two days, I came up with this fun little toy during lunches[...]

Google’s Text To Speech Engine in Flash

I’m not sure how I managed to miss this, but I just happened to run across a ‘new’ (well, newish), albeit still unofficial, offering of Google today: text-to-speech. You can see what few details there are on this Techcrunch post. Basically, it just boils down to this though – you send your phrase to be [...]

Quick Sound Effects Generator


Need some beeps, boops, or bops, to go with your UI or games [...]

Quick QuickBox2D Tip II – Collision Detection

Custom collision detection/handling in QuickBox2D [...]

None of This Runs Eternal


No Flash/Actionscript stuff here. Just me rambling about the upcoming Current 93 concert [...]

Playing Around with the New UndoManager

Included in the Flex 4.0 SDK and the, just released, Flash Professional CS5 lies a new hidden little gem of a class: flashx.undo.UndoManager (although the Flex 4.0 SDK’s been out for awhile, I have to admit I didn’t even notice this until I installed Flash CS5 and started poking around the documentation looking for new [...]

Making Waves

In a previous post, “Digging into the Microphone in Flash Player 10.1″, reader David Law asked in the comments how it would be possible to save .wav files to the server. I wasn’t sure right offhand, but thought I’d spend my lunch hour yesterday looking into it. Well, after reading this quick tutorial on Adobe [...]

Some Drawing Fun and a Bad Movie You’ll Never See

Earlier today, Dave Gillem posted a link on Facebook to an incredible Processing based drawing application. Thought I’d have a go at reproducing something similar in Flash. Well, I failed miserably, but the results were still interesting enough to check out. You can play around with it below. Just mouse down to draw in the [...]

Animating Bezier Curves


The other day I got the notion in my head that I wanted to draw some bezier curves in an animated fashion. I’m sure this has been done a million times before, but sometimes reinventing the wheel can be a good learning experience [...]

My God, It’s Full of Stars…


Just a quick little thing I got an idea for (i.e. pretty much ripped off) while browsing Processing examples.

Another Year, Another Look

As a few folks may have noticed, the blog is looking a little bit different as of today [...]

The Webcam Warholizer


Just a little bit of quick Friday fun with webcam and bitmapata…

More With the JiglibFlash Terrain

Playing around a bit more with the animated JiglibFlash terrain idea from my last post, I wanted to see how it would work in conjunction with a webcam. So, needless to say, you’ll need a webcam to check out the results below.

Rockin and Rollin with the JiglibFlash Terrain


Finally got the chance to play around with the new JiglibFlash height map terrain, today, and have to say I am very impressed [...]