Don't understand why my function doesn't work


#1

Hello everybody, I’m new here.

I just tried to write a function with some logic inside: Check x- and y-coordinates and say “YES” in a textbox when certain conditions are true. But it doesn’t work as I would like to. Can anybody tell me what I’m doing wrong? I’ve modified the drag & drop example so that the message “YES” appears in the infobox when - at runtime - the user drags the ghost to the top-left corner so that x < 200 and y < 300. But my function ‘InTargetZone’ always returns the value 3 … Only the hitTest()-call brings me the answer “Now … YES!”
Here’s the code:

function mouseReleased () {
this.dragging = false;
wert = inTargetZone(200,300);
if (wert==1) {
infobox.setText(wert + ’ YES! ’ );
}
else {
infobox.setText(wert + ’ No.’) ;
}
if(this.hitTest(infobox)) {
infobox.setText(’ Now: YES! ’ );
}

}

function inTargetZone (eins, zwei) {
value = 0;
if (this.x < eins) {
if (this.y < zwei)
value = 1;

    else 
        value = 2;
}
else
   value = 3;
return value;

}