Okay... I didn't knew how to do that since that I'm trying to learn this by myself and I lack knowledge of some "tricks",
I think I managed to refine the code and got ride of all the conditional logic. Thanks for the advice
The code, now, looks like this:
function returnToInitial(k:int){
this["foto"+String(k)+"_mc"].x = this["foto"+String(k)+"_mc"].iniX;
this["foto"+String(k)+"_mc"].y = this["foto"+String(k)+"_mc"].iniY;
}
for(i=1; i<7; i++){ // assign listeners and id nums in a loop using bracjket notation
this["foto"+String(i)+"_mc"].addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
this["foto"+String(i)+"_mc"].num = i;
if(i <= 3){
this["foto"+String(i)+"_mc"].iniX = (160*i)+(i-1)*100;
this["foto"+String(i)+"_mc"].iniY = 100;
}else if(i > 3){
this["foto"+String(i)+"_mc"].iniX = (160*(i-3))+((i-3)-1)*100;;
this["foto"+String(i)+"_mc"].iniY = 260;
}
}
d2 = getChildIndex(foto6_mc);
function startDragging(me:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
setChildIndex(MovieClip(me.currentTarget), d2);
MovieClip(me.currentTarget).startDrag(true);
currentDragged = MovieClip(me.currentTarget);
}
function stopDragging(evt:Event):void {
stage.removeEventListener(MouseEvent.MOUSE_UP, stopDragging);
stopDrag();
checkPosition(currentDragged);
}
function firstCheck(mcR:MovieClip){
for(q = 0; q < icons.length; q++){
if(this[icons[q]].y == 455){
posX = Math.abs(mcR.x - this[icons[q]].x);
if(posX < 10){
returnToInitial(mcR.num);
}
}
}
}
function checkPosition(mc:MovieClip){
firstCheck(mc);
if(mc.y > 420 && mc.y < 490){
mc.y = 455;
for(k=0; k<6; k++){
if(mc.x > 60+(k*135) && mc.x < 120+(k*135)){
mc.x = 90+(k*135);
array[k] = mc.num;
}
}
}
}
What I was trying to do when I moved each dragged object to the level of the foto6_mc was that, everytime I picked an object and moved it along the screen, this object was always above the others and not underneath (when the objects went underneath each others, it happened to me that the object that was going to the initial position was the one above and not the one I was dragging).