mardi 31 janvier 2017

Drag and Drop actionscript outputs

I am doing a drag and drop game wherein if you put the symbol at the target you will gain points and if you put a symbol at the wrong target you will get a deduction on your score. the problem is if ever i put a symbol wherever except the right target it keeps deducting the score. here's the code

stop(); 
var currency:int = 100; 


var objectoriginalX:Number;
var objectoriginalY:Number;
currencytxt.text = currency  + "";
symbol1.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
symbol1.addEventListener(MouseEvent.MOUSE_UP, dropObject);                    


symbol2.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
symbol2.addEventListener(MouseEvent.MOUSE_UP, dropObject);          


symbol3.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
symbol3.addEventListener(MouseEvent.MOUSE_UP, dropObject);          


symbol4.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
symbol4.addEventListener(MouseEvent.MOUSE_UP, dropObject);      


symbol5.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
symbol5.addEventListener(MouseEvent.MOUSE_UP, dropObject);      


symbol6.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
symbol6.addEventListener(MouseEvent.MOUSE_UP, dropObject);      

function pickupObject(event:MouseEvent):void
{
    event.target.startDrag();
    event.target.parent.addChild(event.target);
    objectoriginalX = event.target.x;
    objectoriginalY = event.target.y;

}

function dropObject(event:MouseEvent):void
{
event.target.stopDrag();
var matchingTargetName:String = "target" + event.target.name;
var matchingTarget:DisplayObject = getChildByName(matchingTargetName);
if(event.target.dropTarget != null && event.target.dropTarget.parent == matchingTarget)
{
    event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
    event.target.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
    event.target.buttonMode = false;
     currency = currency + 100; 
     currencytxt.text = currency  + "";
    }
else if(event.target.dropTarget != null && event.target.dropTarget.parent != matchingTarget)
{
    event.target.x = objectoriginalX;
    event.target.y = objectoriginalY; 
     currency = currency - 100; 
     currencytxt.text = currency  + "";
}

 else 
    {
    event.target.x = objectoriginalX;
    event.target.y = objectoriginalY;  
    }
} 

Aucun commentaire:

Enregistrer un commentaire