Forums

ForumsProgramming Forum

Hittesting multiple movie clips with the same identifier? (AS2)

Posted Dec 16, '13 at 5:43pm

mightybob

mightybob

369 posts

Well, doesnt work anyway.

I have your EXACT code inside the actions panel on the main timeline, I have your EXACT code inside the first frame of my coin movie clip, and I triple checked the char instance name making sure it wasn't a stupid mistake.

Code on main timeline:
var coins:Array = new Array();
onEnterFrame = function() {
for(i=0; i < coins.length; i++) {
object = coins[i];
if(char.hitTest(object)) {
object.removeMovieClip();
coins.splice(i,1);
i--;
trace("You win");
}
}
}

Player instance name: char

Code inside of the first frame of the coin movie clip:

this._name = "coin"+_root.coins.length;
_root.coins.push(this);

Char is on main timeline, and so is the coin movie clip.

 

Posted Dec 16, '13 at 6:03pm

arobegamr

arobegamr

130 posts

Replace removeMovieClip() with unloadMovie()

removeMovieClip only works with clips generated with code.

 

Posted Dec 16, '13 at 6:07pm

mightybob

mightybob

369 posts

Still does not work, I don't think you get it.

It doesn't even trace "You win", which means something with the code itself is wrong.

 

Posted Dec 16, '13 at 6:10pm

arobegamr

arobegamr

130 posts

I've checked the code and it works fine for me.

What flash version are you using, and what method are you using to move your char clip?

 

Posted Dec 16, '13 at 6:13pm

mightybob

mightybob

369 posts

I'm using Flash cs6 action script 2, exporting to Flash Player 10.3

To move my char clip I am just doing "_x += speed" etc.

 

Posted Dec 16, '13 at 6:18pm

arobegamr

arobegamr

130 posts

insert this into your enterFrame code:

trace(char);

Tell me what is returned.

 

Posted Dec 16, '13 at 6:36pm

mightybob

mightybob

369 posts

Nothing returns.

 

Posted Dec 16, '13 at 6:37pm

mightybob

mightybob

369 posts

I also tried tracing "Hello world" inside the onEnterFrame. It doesn't trace, so the problem is the enterFrame.

 

Posted Dec 16, '13 at 7:29pm

arobegamr

arobegamr

130 posts

Make sure you're looking at the output panel, not the compiler errors panel

 

Posted Dec 16, '13 at 7:41pm

mightybob

mightybob

369 posts

mhm I've been looking at the output panel

 
Reply to Hittesting multiple movie clips with the same identifier? (AS2)

You must be logged in to post a reply!