In this tutorial, we’ll recreate the Flip Effect used in the iPhone’s UI using Flash CS4 and ActionScript 3.0.
Final Result Preview
Let’s take a look at the final result we will be working towards (click on the ‘i’ button):
Step 1 – Brief Overview
Here’s basically what we’re going to do. We’ll need two Display Objects to flip, one in front that will be on the stage and visible at the beginning, and one that we are going to reveal when the effect is finished; this Object will be in the Library. In this example I’m using MovieClips, but you can use any of the Display Objects (Button, Component, Bitmap, Sprite, Shape, etc.).
We’ll create an ActionsScript 3 Class for the effect, then some code in the .fla to customize the effect as we want.
Step 2
Create a new ActionScript 3.0 document (File > New…). It may be necessary to use the Flash CS4 version; we’re going to export for Flash Player 10 due to the rotationY property being unavailable in older versions. There are a few tricks to get Flash CS3 to export Player 10 contents, you can search the web about doing so if you don’t have CS4.

Step 3
Set the Stage size to 320 x 480px (that’s the iPhone resolution but you can use any size you want), then set a background color. I’m using #111111.

Step 4
Rename the first layer to UI, then create another one and name it Code. Block the Code layer to avoid placing unwanted objects on it.

Step 5
Start creating your First View. This is the view that will be seen by default, you can use and draw anything you want.

Step 6
Convert it to a MovieClip (F8) and set its instance name to firstView.

Step 7
Create the Second view. This is the view that will be visible when the effect is finished.

Step 8
Convert it to a MovieClip, name it SecondView and check the Export for ActionScript checkbox (remember that this view won’t be on stage, we’ll call it from the Actions Panel).

Step 9
Now we have to create an Object which activates the effect; a Button will do the job. Create a button, set its position and name it infoButton. This button will be in the First View. In my example i’ve created the button inside the FirstView MovieClip. You can put it wherever you want, just remember where it is so you don’t get confused in the code.

Step 10
In the Second View, create another button and name it doneButton. This button will flip the view back.

Step 11
Save your work and let’s get into the code!
I’m assuming you already have a basic understanding of ActionScript 3.0. If you have a keyword specific doubt please refer to the Flash Help.
Create a new ActionScript file (File > New…).
Step 12 – Importing Required Classes
Now that you have your AS File ready, start writing:
package Classes
{
/* Import required classes for animation */
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.Strong;
/* Import required classes */
import flash.display.*;
import flash.utils.Timer;
import flash.events.*;
The first three classes handle all the animation we will be using on the effect. In this case, I’m using a Strong easing to get a more iPhone-like flip, but you can modify this to get a different effect.
The other three classes handle the display elements, the Timer object that we’ll use to check the progress of the animation and the last one handles any events that we may use.
Step 13 – Extending the Class
//We need to extend the class so we can use the addChild() method.
public class Flip extends Sprite
{
Extending the Sprite class will make our class inherit all of the methods, properties and functions the Sprite has. In this case we use it to get access to the addChild() method.
Step 14 – Declaring Variables
private var firstView:DisplayObject; private var secondView:DisplayObject; private var initFromSide:String; private var duration:int; private var flipTween:Tween; private var addSecondView:Boolean; //This is used when the Second View IS already on stage and not in the Library, just in case. private var added:Boolean = false; private var timer:Timer = new Timer(1);
Declare variables to use outside the main function (flip), they get their values from the ‘constructor function’ and have self-explanatory names.
Step 15 – The Constructor Function
The constructor function represents the class containing the template from which new object instances are created. This is the function we need to use to call the class.
/* Flip starter function, with some parameters so you can customize your Flip like you want, remember these are the same as the variables */
public function Flip(frontObject:DisplayObject, backObject:DisplayObject, timeInSeconds:int, flipFromSide:String, secondViewIsInLibrary:Boolean):void
{
firstView = frontObject;
secondView = backObject;
duration = timeInSeconds;
initFromSide = flipFromSide;
addSecondView = secondViewIsInLibrary;
animateFirstView(); //This function animates the first part of the flip.
timer.addEventListener(TimerEvent.TIMER, checkFlip); //We check if it's time to animate the Second View
}
Step 16 – The Animate Function
private function animateFirstView():void
{
flipTween = new Tween(firstView,"scaleX",Strong.easeIn,1,0.5,duration/2,true);//This lines are in charge of the scale animation,
flipTween = new Tween(firstView,"scaleY",Strong.easeIn,1,0.5,duration/2,true);//They reduces the view to the half of its size
if (initFromSide == "left") //If the animation starts from left, we animate from the left!
{
flipTween = new Tween(firstView,"rotationY",Strong.easeIn,0,90,duration / 2,true);//This is a key line, it modifies the rotationY property to make the flip
timer.start();// We start the timer to check when we can change the MovieClips
}
else if (initFromSide == "right")
{
flipTween = new Tween(firstView,"rotationY",Strong.easeIn,0,-90,duration / 2,true);
timer.start();
}
}
This function is in charge of animating the First View. It reduces the size of the First View and checks the side parameter to start the animation.
Step 17 – Checking For The Right Position
This function will check the rotationY property to control the animation of the Second View.
private function checkFlip(e:TimerEvent):void
{
if (initFromSide == "left" && firstView.rotationY >= 90)//If the animation was started from left and the First View is ready to switch
{
timer.stop(); //We stop checking when to switch views
firstView.visible = false; //Hides the First View
if (addSecondView && ! added)//If the Second View needs to be added from Library and has not been added
{
secondView.x = firstView.x; //Sets Second View position
secondView.y = firstView.y;
addChild(secondView);//Add Second View
added = true;//Set added to true to avoid adding a lot of Second Views
}
else
{
/* If Second View is in stage */
secondView.x = firstView.x;
secondView.y = firstView.y;
}
animateSecondView();//Animates Second View, the same way the first one is animated, hides the Second View and unhides the First View when done
}
else if (initFromSide == "right" && firstView.rotationY <= -90)
{
timer.stop();
firstView.visible = false;
if (addSecondView && ! added)
{
secondView.x = firstView.x;
secondView.y = firstView.y;
addChild(secondView);
added = true;
}
else
{
/* If Second View is in stage */
secondView.x = firstView.x;
secondView.y = firstView.y;
}
animateSecondView();
}
}
Step 18 – Animating the Second View
This function animates the Second View. It’s almost the same as the first animation function.
private function animateSecondView():void
{
flipTween = new Tween(secondView,"scaleX",Strong.easeOut,0.5,1,duration/2,true);
flipTween = new Tween(secondView,"scaleY",Strong.easeOut,0.5,1,duration/2,true);
if (initFromSide == "left")
{
flipTween = new Tween(secondView,"rotationY",Strong.easeOut,-90,0,duration / 2,true);
firstView.visible = true;
}
else if (initFromSide == "right")
{
flipTween = new Tween(secondView,"rotationY",Strong.easeOut,90,0,duration / 2,true);
firstView.visible = true;
}
}
}
}
Step 19
Save your ActionScript file as ‘Flip.as’.

Step 20 – Using the Class
In your Flash file, open the Actions Panel and write:
import Classes.Flip; //Imports the class, you have to change 'Classes' with your own classes folder.
var flipped:Boolean = false; //We use this variable to know if the First View was already flipped.
var secondView:SecondView = new SecondView(); //Creates a SecondView Object, the one in the Library
var flip:Flip; //This is an instance of our Flip class
function callFlip(e:MouseEvent):void
{
if (! flipped) //If the FirstView isn't already flipped
{
firstView.infoButton.visible = false; //Hides the button so the user can't repeat the effect when its flipping.
flip = new Flip(firstView, secondView, 2, "left", true); //This is the main line, it calls the class indicating wich MovieClips flip, the time the effect will take, wich side to start from, and if the second MovieClip is in the Library.
addChild(flip); //We have to add the class to get the addChild() method to work, this is a very common problem when using addChild() inside a class, now you know! ;)
flipped = true; //Set flipped to true to know that the First View was already animated
secondView.doneButton.visible = true; //Unhide the buttons so we can use them again
secondView.buttonBar.visible = true; //This is just the upper bar in the Second View
}
else if (flipped) //If flipped is true it's time to flip the secondView, you can set new parameters to get a totally diferent animation!
{
secondView.doneButton.visible = false;
flip = new Flip(secondView, firstView, 2, "right", true);
addChild(flip);
flipped = false;
firstView.infoButton.visible = true;
secondView.buttonBar.visible = false;
}
}
firstView.infoButton.addEventListener(MouseEvent.MOUSE_DOWN, callFlip); //Adds the listeners to the buttons
secondView.doneButton.addEventListener(MouseEvent.MOUSE_DOWN, callFlip);
Step 21
Save your work and check that everything is all right. Take a look at the instance names, test your code, search for errors, or maybe even alter the graphics.
Conclusion
Test your movie to see this cool effect in action!
Make sure that everything works as you expected; if not get back to the code or the .fla to take a look. If you can’t find the error, you can Debug your movie by pressing Shift + Command + Return, or going to Debug > Debug Movie.
Remember: you have a lot of options to make the effect just like you want. Play with the parameters, the Display Objects and if there’s something you think is missing, you can always edit the class!
I hope you liked this tutorial, thanks for reading!


Hello,
Thanks so much for this. I got it right when I needed it.
Regards,
Vikrant
Great tutorial!
Here’s a different tutorial for cool 3D flip effect using TweenMax:
http://flexwiz.amosl.com/as3/flying-postcards-tweening-3d-billboard-tutorial/
flash.tutsplus.com to GoogleReader!
Thank you
I got an error:
TypeError: Error #1010: A term is undefined and has no properties.
I made the graphics myself and copy pasted the code from the source file.
Everything looks like it is in working order, but unfortunatly not.
very good tutorilas
great tutorial, do you have actionscript 2 tutorial?
Count me in for the error 1119 and 1067 nightmare.
Error 1067: flip = new Flip(firstView, secondView, 2, “left”, true); //This is the main line, it calls the class indicating wich MovieClips flip, the time the effect will take, wich side to start from, and if the second MovieClip is in the Library.
The 1119 errors pertain to the infoButton commands.
CS4, Mac OS X version
Hi,
Awesome tutorial.
But I’ve increased the width of the background and when the objects flip they leave a trail of their transformation visible underneath. Try to increase the width from 320 to 900 lets say, flip the objects a few times and you’ll see the trail.
Can somebody help me with this?
Tnx.
I’m experiencing the same problem. Does anyone know a solution to this?
Amazing very nice
That is awesome, but I wouldn’t it make more sense to make an i phone flip case?
Hi,
Great Tutorial!
I’m a beginner and I need help from some one on how to make it so I could have other flip things instead of just 2.
So like you press the ‘info button’ and it flips to the second side. The you press the ‘done button’ and it flips to a third side and so one.
I have tried to make it so it goes onto another scene and then repeat the same code (with changes for each side and button) but for some reason its not working.
Is there a way to make it so it is all on the same scene or even frame?
I really need help and I am not as good as all of you are!
I don’t know much as but I am learning.
Thank You!
pretty cool flip effect!
Nice tut, i made a class wich works with TweenMax wich in my opinion is slightly more clean due to no timer being needed and the option to do something when its done.
Feel free to use, just make sure to adjust the package name.
package duskydesigns.models.tools{
import com.greensock.*;
import com.greensock.easing.*
import flash.display.MovieClip;
import flash.display.Stage;
public class pageFlip {
private var theObjectFrom :Object;
private var theObjectTo :Object;
private var theContainer :Object;
private var theFlipRight :Boolean;
private var theOnComplete :Function;
private var theRotationY :Number;
public function to(_objectFrom:Object, _objectTo:Object, _attachTo:Object, _flipRight:Boolean=true, _onComplete:Function=null) {
theObjectFrom = _objectFrom;
theObjectTo = _objectTo;
theContainer = _attachTo;
theFlipRight = _flipRight;
theOnComplete = _onComplete;
theRotationY = (theFlipRight) ? -90 : 90;
TweenMax.to (theObjectFrom, 1, {z: 600, rotationY: theRotationY, ease:Strong.easeIn, onComplete:endFlip});
theRotationY = (theFlipRight) ? 90 : -90;
}
private function endFlip()
{
theContainer.removeChild (theObjectFrom);
theContainer.addChild (theObjectTo);
theObjectTo.x = theObjectFrom.x;
theObjectTo.y = theObjectFrom.y;
theObjectTo.rotationY = theRotationY
theObjectTo.z = 600;
TweenMax.to (theObjectTo, 1, {z: 0, rotationY: 0, ease:Strong.easeOut, onComplete: theOnComplete});
}
}
}
hello, i have problem. I will try to do that for 3 button in firtsview, but didn’t work. How can i do that??
help me!!!!
Hi, I’m extremely new to flash, and I don’t quite understand how you’ve created the first and second views in one layer. Could someone explain this to me? Thanks
Rob
What does this mean? I need help
“Imports the class, you have to change ‘Classes’ with your own classes folder.”
I found a similar tutorial here:
http://premiumcoding.com/flash-as3-tutorial-3d-flip-effect/
Very nice tutorial thanks.
Like so many before me I have increased the size of FirstView and SecondView to 480 x 800 to work on an Android device. I also found that on the flip from FirstView to SecondView SecondView was placed a little low on the screen so I changed some code as follows;
firstView.visible = false;
if (addSecondView && ! added)
{
secondView.x = firstView.x;
secondView.y = firstView.y – 150;
addChild(secondView);
added = true;
}
else
Notice the – 150 in the y line.
This corrected the placement of SecondView but then when flipping back to FirstView it was placed a little too high. So tried to compensate bu changing the following code;
if (addSecondView && ! added)
{
secondView.x = firstView.x;
secondView.y = firstView.y + 150;
addChild(secondView);
added = true;
}
else
This seemed to fix the problem except that in testing on the device I find that if I keep flipping from one view to the next there is a gradual creeping of the view down on the screen so that by the 5th flip the displacement is about 5mm.
Could the author please comment on a possible fix? Perhaps my code fix is not ideal.
Thanks
Paul
OK so now I will answer my own post.
those two shifts must be set to – 155 and plus 155.
Also check the placement of FirstView on the stage (should be centered) and I increased the height of SecondView from 800 to 810.
Seems to work fine now.
Paul