So is your collision testing all in your commented-out setions?
Code:
for (var a in MovieClip(root).dirt) {
Xhit=false;
if (MovieClip(root).dirt[a].hitTestObject(this)==true) {
Xhit=true;
collideX();
}
}
How many elements do you expect to be in "dirt?" Is it just an Array or what?
Assuming it's an Array...
Code:
var dirt:Array = MovieClip(root).dirt;
Xhit=false;
for (var a in dirt) {
if (MovieClip(dirt[a]).hitTestObject(this)==true) {
Xhit=true;
collideX();
break;
}
}
Three changes:
1 set "dirt" before the loop, so I didn't need to keep re-casting "root"
2 set Xhit to false before the loop, so it only does it the once. Before, if the last entry of dirt doesn't collide, then Xhit would return to false for the last go through the loop, even if an earlier entry collided
3 I added the break, since once it's found one collision it doesn't seem to matter if it finds two
I also question the value of testing for Xhit inside the collideY function. What if it hits a corner, where moving just the X position back won't be enough to get it out of the wall? Then it might get stuck.