Code:
_root.hold_mc.trackOne_mc.num = 1;
_root.hold_mc.trackTwo_mc.num = 2;
done = 0;
_root.ball_mc.onEnterFrame = function() {
this._x += 2;
for (i in _root.hold_mc) {
trace(i);
if (_root.ball_mc.hitTest(_root.hold_mc[i]) && done == 0) {
numHit = _root.hold_mc[i].num;
trace(numHit);
done = 1;
}
trace(numHit)
if (numHit != _root.hold_mc[i].num) {
trace("diff");
_root.ball_mc.onEnterFrame = null;
_root.ball_mc.onEnterFrame = function() {
_root.ball_mc._x -= 2;
};
}
}
};
On entering the frame the first time,
1 ) moves ball to the right by 2 pixels
2 ) starts FOR loop
3 ) first IF checks to see if ball is hitting trackTwo, it is not.
4 ) second IF checks to see if numHit (undefined) is not equal to trackTwo num, this is true
5 ) within the IF, sets new function, to replace this one, to move ball to left
note: this will happen the next frame interval, so FOR loop continues
6 ) first IF checks to see if ball is hitting trackOne, it is and done is zero, it is.
7 ) within the first IF, numHit is now set to 1, done is set to 1
8 ) second IF checks to see if numHit is not equal to trackOne num, this is false - they are equal
9 ) that ends the FOR loop
On entering the frame the second and subsequent times,
1 ) Using the new onEnterFrame function (see step 5 above), ball moves left by 2 pixels