all groups > flash actionscript > july 2007 >
You're in the

flash actionscript

group:

Problem with attachMovie and hitTest


Problem with attachMovie and hitTest Shad0wdrag0n
7/10/2007 7:45:21 PM
flash actionscript:
In the flash game I'm making I've decided to try out the attachMovie code to
place the monsters. As an example I have one room that has a giant spider in
it. The code I used on the frame that contains the room is below. The problem
is that the hitTest isn't working. The player MC walks right through the giant
spider without loading the combat .swf movie. Can someone please point out what
I've done wrong? If it matters I've got a main .swf movie which all the other
..swf movies are loaded into (using loadMovieNum). Each location .swf file is
loaded into level 1. When combat occurs the combat .swf is loaded into level 2.

attachMovie("giantSpider", "giantSpider", getNextHighestDepth(), {_x: 530, _y:
340})
if(_root.player.hitTest(giantSpider)){
if(_global.combat1==100){
_global.combat1=0;
loadMovieNum("giantSpider.swf", 2);
_global.speed=0;
}
}
Re: Problem with attachMovie and hitTest kglad
7/11/2007 4:29:58 AM
Re: Problem with attachMovie and hitTest Shad0wdrag0n
7/11/2007 5:42:26 AM
I don't think it's a problem with repeated executions. The frame also has a
Stop(); command, which I thought made it so the frame only loaded once. I even
added a variable to the hitTest. The code was only supposed to run when the
variable was a specific number. Once the player contacted the monster it was
supposed to immediately change the variable to another number, preventing the
hitTest from running again until the variable was changed back. It still didn't
work.
Re: Problem with attachMovie and hitTest kglad
7/11/2007 1:46:57 PM
the problem is not that you are repeatedly executing that hitTest. the problem
is that you are not repeatedly executing that hitTest.

you're checking a hitTest immediately after your spider is attached. if
_root.player is not "hitting" the giantSpider when it's created but later when
_root.player moves, your hitTest will not detect that.
Re: Problem with attachMovie and hitTest Shad0wdrag0n
7/11/2007 6:29:44 PM
Re: Problem with attachMovie and hitTest kglad
7/11/2007 9:50:33 PM
you can start a setInterval() or onEnterFrame loop, but that would be
inefficient because you probably already have some other loop running that
allows player to move. that would be the place to insert your hitTest() so
it's checked every time your player moves.
Re: Problem with attachMovie and hitTest Shad0wdrag0n
7/12/2007 5:38:26 AM
I tried adding the hitTest to the player MC and it seems to be working. Another
problem has arrisen though. When a monster MC is attached to the stage it
appears on all frames, not just the one the attachMovie code is on. Also, when
a MC is attached on layer 1, and a new .swf is loaded into layer 2, the
attached MC can still be seen. Is there a way to make the attached MC only
appear on one frame and only on one layer?
Re: Problem with attachMovie and hitTest kglad
7/12/2007 1:35:50 PM
AddThis Social Bookmark Button