Flash AS3 Tutorial: 3D flip effect
Posted on 07.50 by YUDIES EXPLORER
STEP 1: PREPARING ASSETS IN FLASH
Open Flash and create a new document in AS3. Go to File/Import/Import to stage and import two images. They should be of the same size to achieve a smooth effect. Convert them both to MovieClips (right click and then Convert to Symbol). Name first one adNumber1 and second one adNumber1. Be sure to name instances of movie clips also. You can name them with your names also but these are the names used in source files.Leave both images on the stage as they are, no positioning is needed since we will do that with actionscript.
[amazon_carousel widget_type="SearchAndAdd" width=600" height="200" title="" market_place="US" shuffle_products="True" show_border="False" keywords="flash tutorial, learn flash" browse_node="" search_index="Books" /]
STEP 3: POSITIONING
It is time to put our 3D flip effect to life. First you have to import Tweenlite classes that will take care of our animation.import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.easing.*;
We have defined two sprite objects, add them to stage and then inserted both images into them. Now we have to move our images along x and y axis for half of their width and height to set the rotation point to the center of the sprite:
adNumber1.x = - adNumber1.width/2;
adNumber1.y = - adNumber1.height/2;
adNumber2.x = - adNumber2.width/2;
adNumber2.y = - adNumber2.height/2;
adNumber1.y = - adNumber1.height/2;
adNumber2.x = - adNumber2.width/2;
adNumber2.y = - adNumber2.height/2;
imageC.rotationX = 0;
imageD.rotationX = 0;
imageD.rotationX = 0;
imageC.x = stage.stageWidth - imageC.width;
imageC.y = stage.stageHeight - imageC.height/2
imageD.x = stage.stageWidth - imageC.width;
imageD.y = stage.stageHeight - imageC.height/2;
imageC.y = stage.stageHeight - imageC.height/2
imageD.x = stage.stageWidth - imageC.width;
imageD.y = stage.stageHeight - imageC.height/2;
STEP 4: APPLYING THE 3D EFFECT
We are finally at the fun part. We will implement two functions that will take care of our 3D effect.We will first define two more variables that will take care of animation time and time each image is in still position (time that image is not moving):
We will now set initial position for second image. It has to be set at 90 or -90 degrees and opacity set to 0. First function will rotate first image for 90 degrees (until it is not visible anymore) and then set it’s opacity value to 0. After first part of rotation is completed second one begins. Animation of the second image rotates it to 0 degrees (note that starting position of second one was set to -90). First function has now done it’s job. Second function now sets initial position of first image to -90 degrees and sets opacity to 0. Tweenlite animations now do exactly the same job as in first function (only images are now in different order). After first part of tween is completed we call first function again and so on. Functions will keep calling each other and our 3D flip will repeat infinitely.
function flip3D(){
imageD.rotationX = -90;
imageD.alpha = 0;
TweenLite.to(imageC, animationTime, {alpha:1,delay:imageOnStage,rotationX:90,ease:Quint.easeIn, onComplete:flip3DSecond, overwrite:0})
TweenLite.to(imageD,animationTime, {alpha:1,delay:imageOnStage + animationTime, rotationX:0, ease:Elastic.easeOut, overwrite:0})
}
function flip3DSecond(){
imageC.alpha = 0;
imageC.rotationX = -90;
TweenLite.to(imageD, animationTime, {alpha:1,delay:imageOnStage, rotationX:90,ease:Quint.easeIn, onComplete:flip3D, overwrite:0})
TweenLite.to(imageC,animationTime, {alpha:1,delay:imageOnStage + animationTime, rotationX:0,delay:0, ease:Elastic.easeOut,overwrite:0})
}
imageD.rotationX = -90;
imageD.alpha = 0;
TweenLite.to(imageC, animationTime, {alpha:1,delay:imageOnStage,rotationX:90,ease:Quint.easeIn, onComplete:flip3DSecond, overwrite:0})
TweenLite.to(imageD,animationTime, {alpha:1,delay:imageOnStage + animationTime, rotationX:0, ease:Elastic.easeOut, overwrite:0})
}
function flip3DSecond(){
imageC.alpha = 0;
imageC.rotationX = -90;
TweenLite.to(imageD, animationTime, {alpha:1,delay:imageOnStage, rotationX:90,ease:Quint.easeIn, onComplete:flip3D, overwrite:0})
TweenLite.to(imageC,animationTime, {alpha:1,delay:imageOnStage + animationTime, rotationX:0,delay:0, ease:Elastic.easeOut,overwrite:0})
}
CONCLUSION
Our 3D flip effect is now completed but we’re far from done. If you look carefully you will notice that images are a bit blurry. That happens because of the way Flash renders 3D. In second part of our tutorial I will show you how to solve this issue. Third part of the tutorial will implement a simple 3D engine that will rotate images along all three axis (x,y,z). So stay tuned for more 3D effects! If 3D rotation is not working check if you have Flash player version 10 set as export player. Go to File/Publish Settings and select tag named Flash. Set player to version 10 if it is currently set to 9.
Langganan:
Posting Komentar (Atom)
No Response to "Flash AS3 Tutorial: 3D flip effect"
Leave A Reply