Ciao a tutti, sto modificando un piccolo script trovato su internet che permette di fare il drag and drop di alcune pedine su una matrice di caselle (una specie di gioco degli scacchi)
Le mie pedine sono t0,t1,t2... mentre le caselle sono c0,c1,c2...
Il mio problema si trova nella funzione "test_match(target,obj)" dove ho bisogno di recuperare i nomi delle istanze dei mc che si stanno sovrapponendo (es. t2 sopra c5). Con obj.name ottengo quella del tavolo ma non riesco a ottenere la casella con target.name.
grazie x qualunque aiuto!
//coordinate tavoli
var ori_x;
var ori_y;
//aggiungo listener evento su click del mouse sui tavoli
for each (var item in tavoli)
{
item.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
item.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
item.buttonMode = true;
}
// Define a mouse down handler (user is dragging)
function mouseDownHandler(evt:MouseEvent):void {
var object = evt.target;
ori_x = object.x
ori_y = object.y
object.useHandCursor = true;
object.startDrag();
}
function mouseUpHandler(evt:MouseEvent):void {
var obj = evt.target;
// obj.dropTarget will give us the reference to the shape of
// the object over which we dropped the circle.
var target = obj.dropTarget;
// If the target object exists the we ask the test_match function
// to compare moved obj and target where it was dropped.
if (target != null)
{
test_match(target, obj);
}
obj.stopDrag();
}
//verifica il posizionamento del tavolo spostato sulle caselle della matrice
function test_match(target,obj) {
// test if the pairs match
if (obj != null)
{
obj.x = target.x;
obj.y = target.y;
obj.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
obj.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}
else
{
/*obj.x = ori_x;
obj.y = ori_y;*/
}
}

Rispondi quotando