Some things to fix :
(1) Give your variables a data type. Saying var s = 0; suggests that s is a numerical variable, right? Well score.text expects a String not Number so you must use casting to convert. Try :
var s : int = 0; //define a numerical variable
score.text = String(s); //cast number into String type (for usage as text)
(2) Don't put your functions inside a For-loop!!! Don't even put functions inside other functions (unless you know what an Anonymous Function is, and you can justify needing it).
(3) You can shorten some code typing by :
- Incrementing? Use
s += 10 to avoid longer s = s + 10;. Can also be -=, /= etc.
- If setting same value to multiple variables just chain like so:
cheese.x = cheese.y = -50;
(4) Don't try to access mixed[i] by mixed.length. Since length is 5 at some point the compiler sees an instruction like : mixed[5].addEventListener...
However an array starts at zero for first item so you should understand the fifth item is really at mixed[4].addEventListener....
That other mixed[5].something (same as : mixed[mixed.length].something) does not exist.
PS : I would have thought that setting i < mixed.length would have protected against going over the array size, since if i must be smaller than .length then i == 5 could never happen.
Anyways... This code below is untested (no AS3 compiler here) but try the following :
var s : int = 0;
score.text = String(s);
var mixed:Array = new Array;
mixed.push(orange); mixed.push(cheese);
mixed.push(lobbio); mixed.push(meat); mixed.push(fish);
for (var i:uint = 0; i <= (mixed.length-1); i++)
{
mixed[i].addEventListener(MouseEvent.MOUSE_DOWN, drag);
mixed[i].addEventListener(MouseEvent.MOUSE_UP, drop);
} //end "For" loop
function drag(e) : void { e.target.startDrag(); }
function drop(e) : void
{
e.target.stopDrag();
if( (cheese.y > 50 && cheese.y < 150) && (cheese.x > 480 && cheese.x < 570) )
{
cheese.x = cheese.y = -50;
s += 10; //# achieves same thing as... s = s + 10;
score.text = String(s);
}
if( (Sprite(e.currentTarget).y > 50 && Sprite(e.currentTarget).y < 150) && (Sprite(e.currentTarget).x > 480 && Sprite(e.currentTarget).x < 570) )
{
Sprite(e.currentTarget).x = Sprite(e.currentTarget).y = -50;
s += 10;
score.text = String(s);
}
} //end Function "drop"