package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.MovieClip;
public class Cards extends Sprite
{
private var maxNum:int=64;
private var frame_num:int=0;
private var frames_arr:Array=[];
private var card_arr:Array=[];
private var card:Card;
private var mc1:Card;
private var mc2:Card;
public function Cards():void
{
init();
}
private function init():void
{
for(var i:int=0;i<maxNum/2;i++)
{
card=new Card();
addChild(card);
frame_num=Math.random() * 18+2;
frames_arr.push(frame_num);
card.gotoAndStop(frame_num);
card.buttonMode=true;
card_arr.push(card);
card.addEventListener(MouseEvent.CLICK,onclick);
}
for(var j:int=maxNum/2;j<maxNum;j++)
{
card=new Card();
addChild(card);
frame_num=frames_arr[j-maxNum/2];
card.gotoAndStop(frame_num);
card.buttonMode=true;
card_arr.push(card);
card.addEventListener(MouseEvent.CLICK,onclick);
}
sort();
}
private function sort():void
{
for(var i:int=0;i<8;i++)
{
for(var j:int=0;j<8;j++)
{
card_arr[i * 8+j].x=45 * j;
card_arr[i * 8+j].y=45 * i;
}
}
}
private function onclick(e:MouseEvent):void
{
var mc=e.currentTarget as Card ;
if(mc1==null)
{
mc1=mc;
mc1.alpha=0.2;
trace(2);
}
else if(mc2==null)
{
mc2=mc;
mc2.alpha=0.2;
trace(mc1.currentFrame,mc2.currentFrame);
if(mc1.currentFrame==mc2.currentFrame)
{
removeChild(mc1);
removeChild(mc2);
mc1=null;
mc2=null;
}
else
{
mc1.alpha=1;
mc2.alpha=1;
mc1=null;
mc2=null;
}
}
}
}
}