Other Websites

  • SeaCloud9 Interactive
  • SeaCloud9 Commercial Development
  • i-os
  • stArcade9

Brendon Smith Social Networks

  • On Linkedin
  • Bookmarks
  • On Twitter
  • On Facebook
Open ↓ Close ↑
  • Home
  • Subscribe
Browse: Home / 3d, ActionScript, Adobe, Flash, i-create, QuickTip / Simple Flip3D in ActionScript3
i-create | therefore-i am
i-create | therefore i-am | a blog about opensource technology and rich internet applications
 

Simple Flip3D in ActionScript3

By Brendon Smith on April 11, 2010

 

This code will show you how to develop a simple native actionscript3d Class it shows you two different methods you could use to develop your own flip 3d effect in ActionScript3 this uses Flash Player 10. This code also only uses the built in functionality of Flash with the exception of the use of Tweener Class used in one of the way you could potentially animate it. You could also use a 3d library like Papaervision3D or Away3D and these libraries would give your more options and greater control but this is just a simple 3D flip using rotationX property of flash. This shows you how you might go about creating a Rolodex like effect in flash. I have also made the code more reusable because it is a class of its own that can be linked to a flash movie clip dragged on the stage and then called and reused easily. One of the many great features of flash is the ability to change visual objects into classes (Visual OOP) of there own rapidly! I have written code that basically once applied to a movie clip will randomly display a frame you will see this in the class you can expand it add new frames to the array etc.. What it does is randomly picks a frame displays the image and then once clicked will rotate the X property of the movie to about 84 degrees and disappear. It also shows you two different ways you could accomplish this task. One way the way I like the best is to use Tweener an animation library that has been around in the Flash community for years. Tweener frees you from the time line in other words your animation is time based instead of frame based. Time based is completely the way to go this ensures your users that they will have the same effect and performance regardless. Time based animation effects have been around in the Flash community for years actually Robert Penner wrote an excellent book Programming Macromedia Flash MX years ago I would recommend this book to anyone who is interested in learning the inner workings of easing equations for animation. His book inspired many animation libraries to be built and his equations can actually be found in many JavaScript animation libraries as well. Frame based animations tend to not always run at the speed of the Timeline FPS as a result they can lag and display a jumpy performance. If you would like a frame based approach I have included one that show you you can call a click function and then tie it to an EnterFrame event and that triggers the animation if you so please.

SimpleFlip3D in Flash

Call the Class from the Frame

var flipID:uint = new uint(1);
var sc9MainPortImg1:sc9MainPortImg = new sc9MainPortImg();
addChild(sc9MainPortImg1);
sc9MainPortImg1.x=0;
sc9MainPortImg1.y=55;
sc9MainPortImg1.name = "sc9Img"+flipID;
sc9MainPortImg1.buttonMode = true;
sc9MainPortImg1.addEventListener(MouseEvent.MOUSE_DOWN, sc9PortClick);
 
function sc9PortClick(e:MouseEvent){
var sc9MainPortImg1:sc9MainPortImg = new sc9MainPortImg();
addChildAt(sc9MainPortImg1,1);
sc9MainPortImg1.x=0;
sc9MainPortImg1.y=55;	
sc9MainPortImg1.name = "sc9Img"+flipID++;
trace(sc9MainPortImg1.name);
sc9MainPortImg1.buttonMode = true;
sc9MainPortImg1.addEventListener(MouseEvent.CLICK, sc9PortClick);
}

The actual Simple Flip 3D Class

package {
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.events.*;
	import flash.display.*;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.BlurFilter;
	import flash.net.LocalConnection;
	import fl.transitions.*;
	import caurina.transitions.Tweener;
	import flash.external.ExternalInterface;
 
	public class sc9MainPortImg extends MovieClip {
		public var n:Number;
		public function sc9MainPortImg():void {
			randomFrame();
			this.addEventListener(MouseEvent.CLICK, spinClick);
		}
 
		public function randomFrame():void{
			var frameArray:Array = new Array();
			frameArray[0]=1;
			frameArray[1]=2;
			frameArray[2]=3;
			frameArray[3]=4;
			// Get random number created
			n=randRange(1,4);
			trace(n);
			trace(frameArray);
			// gotoAndStop Frame lable name
			this.gotoAndStop(frameArray[n]);
		}
 
		public function spinClick(e:MouseEvent):void{
			//this.addEventListener(Event.ENTER_FRAME, spin); --> Enable for Frame Based Animation Example 
			var open_tween={rotationX:-84,alpha:0.0,time:20,transition:"easeoutelastic",delay:0};
			Tweener.addTween( this, open_tween);
		}
 
		public function spin(e:Event){
			this.rotationX -= 2;
			if(this.rotationX == -84){
				this.visible = false;
				this.removeEventListener(Event.ENTER_FRAME, spin);
			}
		}
 
		public function randRange(min:Number, max:Number):Number {
				// Generate a number between and including min - max
				var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
				return randomNum;
		}
	}
}

Launch Experiment / Download Code

  • Share/Bookmark

Related posts:

  1. Tweet Tank in Away3D and Hype
  2. Tweet Tank in Away3D and Hype pt. 2
  3. ActionScript3 SharedObject / FlashVars
  4. Fun with Yahoo! Pipes JSON – C# – ActionScript3
  5. 404 Errors Hyped With PaperVision3d pt. 2

Posted in 3d, ActionScript, Adobe, Flash, i-create, QuickTip | Tagged 3d, ActionScript, Experiment, Flash, QuickTip

Brendon Smith

GUI Development, Action Script, Java Script, .NET, AJAX, Java, PHP, CakePHP, Mashup Development, Flash, Silverlight, C#, XML, SQL, Apache, IIS, Photoshop, Fireworks,etc.. Oh, and Biking and Camping

blog comments powered by Disqus
« Previous Next »
 
 

3d ActionScript Adobe Air Android Apollo Apple art as3 Away3D C# CakePHP CSS Experiment Flash Flash Develop Flex Games Generative Design Google HTML5 hype JavaScript Joshua Davis JQuery JSON Life Linux MashUp OpenSource Open Source PaperVision3D PC History Processing quick tip RIA Silverlight Technology/Internet travel twitter Web webGL Webware XML Yahoo Pipes

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

  • Monthly
  • Yearly
  • Links
  • August 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • agit8
  • Away3D
  • Ben Nadel
  • Bit-101
  • Bruce Jawn
  • Causecast
  • D.I.Y.
  • Dr Woohoo
  • draw.logic
  • Flight404
  • Flong
  • generatorX
  • gSkinner
  • haXe
  • Jonathan Snook
  • Joshua Davis
  • Jot
  • Kirupa
  • LifeHacker
  • Make
  • Minor White
  • Mr Doob
  • NihiLogic
  • NurseOnTheRun
  • octane42
  • OpenFrameWorks
  • Processing
  • PV3D
  • Senocular
  • Sephiroth
  • ShineDraw
  • Stroep
  • SWX
  • Tech News
  • Toxi
  • UnitZeroOne
  • World We Live In
  • ZeusLabs

Photos

100_1024.JPG

Recent Comments

  • seacloud9 on Tweet Tank in Away3D and Hype pt. 2
  • Brendon Smith on Tweet Tank in Away3D and Hype pt. 2

RSS LifeStream

  • Elysium
  • Giles Bowkett: Archaeopteryx: A Ruby MIDI Generator
  • Grant Nestor » Blog Archive » Generative music, huh?

Copyright © 2010 i-create | therefore-i am.