Skip to main content
Known Participant
May 5, 2007
Answered

Hit test / collision detection and AS

  • May 5, 2007
  • 2 replies
  • 585 views
Hi there,
I am trying to figure a way to run a hit-test to an object on the stage. The object is appearing via actionscript (Block)
and the object that hits it is Player.
This will work once I put the Block on the stage not manually, and not via actionscript, but I want to use code to call the block because i am calling several blocks.
See attached code...
Could anyone please tell me what am I doing wrong?!
is it not possible this way?

Thanks!
This topic has been closed for replies.
Correct answer MajiDfn
Dear adamlewen
If you want to delete each movieclip hittest you should do it in a "for" loop. so you can detect the hit test and do the corresponding visual effect .
here is a sample file: take a look ...
you have some problem with naming movieclips I think ...
you have duplicated items in your array which cause conflict

http://www.parspake.com/majid/flash/adamlewen.fla

good luck and feel free to contact me if you have further problem
regards
MajiD


2 replies

May 5, 2007
Block only contains a reference to the last clip attached. You can either loop through the array within your onEnterFrame or hitTest the other way round
eg/within your loop
Block.onEnterFrame = checkHit
//outside loop
function checkHit(){
if(this.hitTest(_root.Player)) {
//dostuff
edit/or if it doesn`t matter which clip hits Player -do as above suggested
adamlewenAuthor
Known Participant
May 5, 2007
Hi MajiDfn
Thanks for that,
now the score and trace do react :)
but they (the Blocks) won't gotoAndStop another frame and also won't obey a removeMovieClip in the if statement...

might the problem be in the way I distribute the Blocks?

Thanks again!

MajiDfnCorrect answer
Inspiring
May 5, 2007
Dear adamlewen
If you want to delete each movieclip hittest you should do it in a "for" loop. so you can detect the hit test and do the corresponding visual effect .
here is a sample file: take a look ...
you have some problem with naming movieclips I think ...
you have duplicated items in your array which cause conflict

http://www.parspake.com/majid/flash/adamlewen.fla

good luck and feel free to contact me if you have further problem
regards
MajiD


Inspiring
May 5, 2007
Hi
I don't know whether or not I got the whole Idea, but you should check the hit test with _root.BlockHolder instead of _root.Block !

if it's doesn't solve your problem please explain it more or even send a sample file.
regards
MajiD