Friday, November 5, 2010
Card Flip in Action Script3.0

Example:
card_mc.addEventListener(MouseEvent.CLICK,cli);
function cli(event:MouseEvent)
{
if(card_mc.currentFrame==1)
startFlip(2)
else
startFlip(1)
}
var flipStep:uint;
var isFlipping:Boolean = false;
var flipToFrame:uint;
/** begin the flip, remember which frame to jump to **/
function startFlip(flipToWhichFrame:uint)
{
isFlipping = true;
flipStep = 10;
flipToFrame = flipToWhichFrame;
card_mc.addEventListener(Event.ENTER_FRAME, flip);
}
/** take 10 steps to flip **/
function flip(event:Event)
{
flipStep--; // next step
if (flipStep > 5)
{ // first half of flip
card_mc.scaleX = .2*(flipStep-6);
}
else
{ /** second half of flip **/
card_mc.scaleX = .2*(5-flipStep);
}
/** when it is the middle of the flip, go to new frame **/
if (flipStep == 5)
{
card_mc.gotoAndStop(flipToFrame);
}
/** at the end of the flip, stop the animation **/
if (flipStep == 0)
{
card_mc.removeEventListener(Event.ENTER_FRAME, flip);
}
}
...CHeeRS...

Subscribe to:
Posts (Atom)