Flash - Drag and drop spil
Kan nogen hjælpe? Jeg har stykket et drag and drop spil sammen, hvor man skal matche otte ord med otte billeder. Se det her: http://ipress.dk/flash/Jeg vil gerne forbedre det så ordene droppes præcis i midten af box og ikke som nu kan droppes på kanten. Jeg vil også gerne have scriptet til at sende ordet tilbage til start, hvis det droppes i den forkerte box. Jeg ved ikke hvilken version af Actionscript der er brugt, men scriptet ser således ud:
var hits = 0;
// Register mouse event functions
tejanos.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
tejanos.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
vestido.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
vestido.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
corbata.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
corbata.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
falda.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
falda.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
camiseta.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
camiseta.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
chaqueta.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
chaqueta.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
camisa.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
camisa.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
gafas.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
gafas.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
// Define a mouse down handler (user is dragging)
function mouseDownHandler(evt:MouseEvent):void {
var object = evt.target;
// we should limit dragging to the area inside the canvas
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();
}
function test_match(target,obj) {
// test if either one of the four pairs match
if ( (target == box_corbata && obj == corbata) ||
(target == box_tejanos && obj == tejanos) ||
(target == box_vestido && obj == vestido) ||
(target == box_camiseta && obj == camiseta) ||
(target == box_camisa && obj == camisa) ||
(target == box_chaqueta && obj == chaqueta) ||
(target == box_gafas && obj == gafas) ||
(target == box_falda && obj == falda) )
{
// we got a hit
hits = hits+1;
textField.text = "Rigtigt. Flot";
// make the object transparent
obj.alpha = 0.5;
// kill its event listeners - object can't be moved anymore
obj.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
obj.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
// Test if we are done
if (hits == 8)
{
textField.text = "Godt gået, opgaven er løst";
}
}
else
{
textField.text = "Forkert. Prøv igen";
}