vendredi 9 décembre 2016

Drag and drop game sort items to three targets

Please I need some help. I have spent 2 weeks trying to make a drag and drop game In cs4 actionscript 3.0 and am about to give up. I have gotten help so far, but the best suggestion I got was try and start from scratch instead of decompiling someone else's work. so here it is I have an array that looks like this

var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";

I need three targets, and the ability to place the name of the item in my array (this is just a short piece of it) on the screen, if it is dropped on the target matching the answerdest number tor that item it is placed in a column, and the next item my array appears. If not it returns to its starting position. This seems like it should be easy to do but I am not a computer teacher I am a science teacher that is trying to make something for my student to use. I have basic coding skills for cs4.

This is as far as i have gotten but can not Figure out how to get the drag and drop part to check if it is in the correct spot. And get to to create a new drag-able if the answer is correct. I have created an answer target named "Answer1",

var objectoriginalX:Number;
var objectoriginalY:Number;
Atom.buttonMode = true;
Atom.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Atom.addEventListener(MouseEvent.MOUSE_UP, dropObject);

Matter.buttonMode = true;
Matter.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
Matter.addEventListener(MouseEvent.MOUSE_UP, dropObject);

        function pickupObject(event:MouseEvent):void {
        event.target.startDrag();

        event.target.parent.addChild(event.target);

        }

var dropCount:int = 0;
var dbCount:int=0;
var dbutton0;
    function dropObject (event:MouseEvent):void
{
    {
    event.target.stopDrag();

    var targetName = Answer1;
    trace (targetName);
    var matchingTarget:DisplayObject = getChildByName(targetName);
    if (event.target.dropTarget != null && event.target.dropTarget.parent == answerdest[1])

        {
            event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
            event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
            event.target.buttonMode = false;
            alpha = .8
            dropCount ++;
            event.target.x = 10
            event.target.y = (Number(dropCount) * 100);
            trace ("hit");




            trace (dropCount);
        } else 
        {
        event.target.x = 100;
        event.target.y = 111;
        trace ("miss");
        }

    } 
}


var answername:Array = new Array();
var answerdest:Array = new Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "Nuts and boltsl";
answerdest[1] = "Answer1";
answername[2] = "water";
answerdest[2] = "2";
answername[3] = "gold";
answerdest[3] = "3";
answername[4] = "Iron";
answerdest[4] = "3";
text3
text3.text = answername[1];

var myText:TextField = new TextField();
Atom.addChild(myText);
myText.text = answername[1] ;

Thanks for your help. I do not know if I am even on the correct track to do what I need it to do.

Aucun commentaire:

Enregistrer un commentaire