package { import flash.display.*; import flash.events.*; public class card extends MovieClip{ var total; var theFace = new String; var myFront; var myBack = new cardBack(); var showingFace; //flipping variables private var flipStep:uint; private var isFlipping:Boolean = false; public function suicide() { this.showingFace = null; this.startFlip(); } public function card (myFace, myTotal){ addEventListener (MouseEvent.CLICK, clickCard); //assign card's face value and total from arguments total = myTotal; theFace = myFace; // Set up the cardFront to display the content myFront = new cardFront(myFace); showingFace = myBack; addChildAt(myBack,0); } // A basic start flip function public function startFlip() { isFlipping = true; flipStep = 10; this.addEventListener(Event.ENTER_FRAME, flip); } // The meat of the Flip animation sequence is here public function flip(event:Event){ flipStep--; //next step if (flipStep > 5) { this.scaleX = .2*(flipStep-6); } else { this.scaleX = .2*(5-flipStep); } if (flipStep == 5) { swapCardFace(); } if (flipStep == 0) { this.removeEventListener(Event.ENTER_FRAME, flip); } } // This call will toggle the showingFace to either the front or back side. public function swapCardFace(){ if (showingFace == myFront) { showingFace = myBack; this.removeChildAt(0); this.addChildAt(myBack,0); } else if (showingFace == myBack) { showingFace = myFront; this.removeChildAt(0); this.addChildAt(myFront,0); } else { this.removeChildAt(0); this.addChildAt(null,0); } } // What happens when a card is clicked? public function clickCard(event:MouseEvent) { startFlip(); } } }