[COLOR=#000000][FONT=verdana]I updated a catch via collision detection game to AS2 and noticed that only the first 3 out of 5 objects are being detected. All 5 are detected in AS1. If I comment out the last 2 all is fine. Just can’t spot the mistake or what differs between the first three and last two. Updated single quotes to double quotes, but that was not it.[/FONT][/COLOR]
[LEFT][COLOR=#000000]//this produces random balls that fall from the sky[/COLOR][/LEFT]
depth = 0;allBalls = new Array();function makeOne() { if(seconds>0){ clearInterval(ranOneID); ran = (Math.random()*4000)+1000; ranOneID = setInterval(makeOne, ran); One = _root.attachMovie("circle", "circle"+depth, depth++); allBalls.push(One); //trace(allBalls); One._x = Math.random()*550; One._y = -50; One.speed = (Math.random()*10)+2; One.onEnterFrame = function() { this._y += this.speed; if (this._y>Stage.height) { updateScore(-5); for (i=0; i<allBalls.length; i++) { if (this == allBalls*) { allBalls.splice(i, 1); } } this.removeMovieClip(); } } };}function makeTwo() { if(seconds>0){ clearInterval(ranTwoID); ranTwoID = setInterval(makeTwo, ran); Two = _root.attachMovie("square", "square"+depth, depth++); allBalls.push(Two); //trace(allBalls); Two._x = Math.random()*550; Two._y = -100; Two.speed = (Math.random()*9)+2; Two.onEnterFrame = function() { this._y += this.speed; if (this._y>Stage.height) { updateScore(-5); for (i=0; i<allBalls.length; i++) { if (this == allBalls*) { allBalls.splice(i, 1); } } this.removeMovieClip(); } } };}function makeThree() { if(seconds>0){ clearInterval(ranThreeID); ranThreeID = setInterval(makeThree, ran); Three = _root.attachMovie("three", "three"+depth, depth++); allBalls.push(Three); //trace(allBalls); Three._x = Math.random()*550; Three._y = -100; Three.speed = (Math.random()*8)+2; Three.onEnterFrame = function() { this._y += this.speed; if (this._y>Stage.height) { updateScore(-5); for (i=0; i<allBalls.length; i++) { if (this == allBalls*) { allBalls.splice(i, 1); } } this.removeMovieClip(); } } };}// NOT BEING CAUGHT ON COLLISIONfunction makeFour() { if(seconds>0){ clearInterval(ranFourID); ranFourID = setInterval(makeFour, ran); Four = _root.attachMovie("four", "four"+depth, depth++); allBalls.push(four); //trace(allBalls); Four._x = Math.random()*550; Four._y = -100; Four.speed = (Math.random()*7)+2; Four.onEnterFrame = function() { this._y += this.speed; if (this._y>Stage.height) { updateScore(-5); for (i=0; i<allBalls.length; i++) { if (this == allBalls*) { allBalls.splice(i, 1); } } this.removeMovieClip(); } } };}// NOT BEING CAUGHT ON COLLISIONfunction makeFive() { if(seconds>0){ clearInterval(ranFiveID); ranFiveID = setInterval(makeFive, ran); Five = _root.attachMovie("five", "five"+depth, depth++); allBalls.push(five); //trace(allBalls); Five._x = Math.random()*550; Five._y = -100; Five.speed = (Math.random()*6)+2; Five.onEnterFrame = function() { this._y += this.speed; if (this._y>Stage.height) { updateScore(-5); for (i=0; i<allBalls.length; i++) { if (this == allBalls*) { allBalls.splice(i, 1); } } this.removeMovieClip(); } } };}makeOne();makeTwo();makeThree();makeFour();makeFive();_root.attachMovie("slider", "slider_mc", -1);slider_mc._y = Stage.height-20;slider_mc._x = 300;slider_mc.onMouseMove = function() { this._x = _xmouse; if ( this._x >=575){this._x=575;} if ( this._x <= 30){this._x=30;} updateAfterEvent(); };Mouse.hide();//_root.createEmptyMovieClip("watchCollision", -2);watchCollision.onEnterFrame = function() { for (i=0; i<allBalls.length; i++) { if (allBalls*.hitTest(slider_mc)) { //trace('we hit the slider'); allBalls*.removeMovieClip(); allBalls.splice(i, 1); updateScore(10); } }};score = 0;function updateScore(amount) { score += amount; score_txt.text = score;} [LEFT][COLOR=#000000]updateScore(0);[/COLOR][/LEFT]
There is also a timer
_global.seconds = 10;var miliseconds = 10;
function tellTime() {
if (miliseconds<10) {
time_txt.text = seconds+":"+"0"+miliseconds;
} else {
time_txt.text = seconds+":"+miliseconds;
}
miliseconds--;
if (miliseconds<0) {
miliseconds = 10;
seconds--;
}
if (seconds<0) {
clearInterval(id);
time_txt.text = "Game Over";
gotoAndPlay(50);
}
}
id = setInterval(tellTime, 100);
stop();