Skip to main content
Inspiring
July 21, 2014
Answered

remove array when touch a movieClip (hitTestObject)

  • July 21, 2014
  • 1 reply
  • 1186 views

Hi all,

I'm making an AS3 platform game.

My player can shoot bullets. If a bullet touch an enemy, it will be removed.

for (var j:int = 0; j < bulletList.length; j++) // for each bullet in the bulletList

  {

  if (enemies.mc.hitTestObject(bulletList) ){

  trace("Bullet and Enemy are colliding");

  enemyDie(i)

  bulletList.removeSelf();

  }

But now I'd like to remove the bullet if it touch a movieClip on the stage (with the instance "tree_mc"). And I can't figure out how to do so...

I've tried this :

var tree_mc;

for (var j:int = 0; j < bulletList.length; j++){

if(tree_mc.hitTestObject(bulletList)){

  trace("bullet hit tree");

  }

But it's not working.

Do you know how I can do that ?

Thank you

This topic has been closed for replies.
Correct answer Stephdidou

Show where you have assigned the Main.as file as your document class file.


Found the problem !

Here what I did :

tree = new Object();

tree.mc = gamelevel.tree;

for (var j:int = 0; j < bulletList.length; j++){ 

if(tree.mc.hitTestObject(bulletList)){ 

  trace("bullet hit tree"); 

  } 

1 reply

Ned Murphy
Legend
July 21, 2014

Do not declare the tree_mc variable (get rid of line 01).  Creating a new variable is not gong to be the same tree_mc. 

Inspiring
July 21, 2014

Ok, but I do so I've got this error : error 1120: Access of undefined property

Ned Murphy
Legend
July 21, 2014

Ok, don't.   If you mean you removed that line then the problem is likely that you did not name the tree_mc that name, or it is otherwise not present when the code executes.  What is the entire error message?