afarin.visible = false;
/*afarin.visible = true;*/
var dragArray:Array = [square,circle,triangle];
var matchArray:Array = [squareMatch,circleMatch,triangleMatch];
var currentClip:MovieClip;
var startX:Number;
var startY:Number;
//--------------------------------
var matchesNum:int = 0; // اضافه شد
//--------------------------------
for (var i:int = 0; i < dragArray.length; i++)
{
dragArray[i].buttonMode = true;
dragArray[i].addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
matchArray[i].alpha = 0.2;
}
function item_onMouseDown(event:MouseEvent):void
{
currentClip = MovieClip(event.currentTarget);
startX = currentClip.x;
startY = currentClip.y;
addChild(currentClip);//bring to the front
currentClip.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
}
function stage_onMouseUp(event:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
currentClip.stopDrag();
var index:int = dragArray.indexOf(currentClip);
var matchClip:MovieClip = MovieClip(matchArray[index]);
if (currentClip.hitTestObject(matchClip))
{
//a match was made! position the clip on the matching clip:
currentClip.x = matchClip.x;
currentClip.y = matchClip.y;
//make it not draggable anymore:
currentClip.removeEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
currentClip.buttonMode = false;
// اضافه شد -------------------------------------
matchesNum++;
if (matchesNum == matchArray.length)
{
afarin.visible = true;
}
//---------------------------------------------
}
else
{
//match was not made, so send the clip back where it started:
currentClip.x = startX;
currentClip.y = startY;
}
}