Jump to content


Flash Game Actionscript


  • You cannot reply to this topic
10 replies to this topic

#1 Tromac

    Young Padawan

  • Members
  • Pip
  • 56 posts

Posted 02 November 2006 - 07:00 AM

Im trying to make a space invader's like game in flash, but for some reason the bullets fly right past the enemies. It's as if the hittest doesnt detect the bullet MC.

This is my hitTest code on the bullet:
	// If bullet hit nme, nme loose life & terminate
	if (_level10["nme"+i].hitTest(this._x, this._y, true) ) {
		_level10["nme"+i].life -= random(5);
		this.removeMovieClip();
	}

The same code works fine with my "ship" and "enemy", but i think thats because the ship is the one loosing "health" and has a static variable name, unlike my enemies.

Any help would be greatly appreciated :D

Edited by Tromac, 02 November 2006 - 07:01 AM.


#2 PixelHiveDesign

    Young Padawan

  • Members
  • Pip
  • 83 posts
  • Gender:Male

Posted 02 November 2006 - 09:46 AM

The snippet you posted would work fine assuming:
* variable i is defined on the bullet.
* the check is executed every frame.
* nme mc's are on _level01.

Try using the trace function to track down the problem.

Otherwise, post the full function that you are working with.

Max (PHD)

#3 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 02 November 2006 - 03:26 PM

I sometimes have problems with the shapeFlag. So just try it the simpler way:
if (_level10["nme"+i].hitTest(this) ) {

#4 Tromac

    Young Padawan

  • Members
  • Pip
  • 56 posts

Posted 03 November 2006 - 10:06 PM

Thanks for the help guys :D

I did what you's both said, but no luck. I've made a couple of changes, like changing all _level10's to _root's, which does the same thing. It wasn't needed as I know they were on level 10 (trace said so), but it saves confusion.

Ill post my fla if anyone is willing to take a look.

Thanks a lot :wtf:

#5 Tromac

    Young Padawan

  • Members
  • Pip
  • 56 posts

Posted 04 November 2006 - 12:33 AM

Here's the link: Continuum.fla

#6 Tromac

    Young Padawan

  • Members
  • Pip
  • 56 posts

Posted 08 November 2006 - 01:41 AM

I've made another change. I have changed the _root["name"+i] to _root.name[i].

There doesn't seem to be any difference, except when i run a trace on _root.bullet[i], it says undefined, where before is said _level10.bullet2 or whichever one.

#7 Tromac

    Young Padawan

  • Members
  • Pip
  • 56 posts

Posted 09 November 2006 - 05:00 AM

Is P2L dead or something? :(

When i used to come on here not too long ago, the forums were buzzing with people. These days no one is around. :laugh:

I was the last person to make a post in Flash, and that was a few days ago :D

#8 Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 09 November 2006 - 05:45 AM

Sorry, but I never found a solution for it. I downloaded the fla, but I couldn't see the problem. I'll have a go again later.

#9 Eggy

    Young Padawan

  • Members
  • Pip
  • 21 posts

Posted 09 November 2006 - 09:22 PM

Don't worry mate, your problem is simple, simply change it to -


if (_level10["nme"+_root.i].hitTest(this._x, this._y, true) ) {
_level10["nme"+_root.i].life -= random(5);
this.removeMovieClip();
}



Everytime you use "i" put _root. in front of it, in your ship and bullet and it works. Remember, if you just put "i" by itself then that variables is only counted for the movieclip its in. You need to put _root. in front so it then checks in every MC.

#10 Tromac

    Young Padawan

  • Members
  • Pip
  • 56 posts

Posted 10 November 2006 - 06:17 AM

Thanks SOOOO much guys for the help ;)

Thanks a lot d4rkst0n3, i appreciate your input and help :)

And thank you too Eggy, I can't believe it was that simple, although I half expected it to be :D

#11 Eggy

    Young Padawan

  • Members
  • Pip
  • 21 posts

Posted 10 November 2006 - 09:54 AM

No worries man ;)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users