Copy link to clipboard
Copied
Hey I have a movie clip with a layout of
1. PEnemy
2. Enemy
3. enemy
then animations and on some frames a MC with an instance name of 'hit'
My movie clip animates and I want to detect hit Test with another child from another movie clip called 'you' with a child MC called 'target'
So bacicly I want
PEnemy.Enemy.enemy.hit to hitTest you.target
I dont understand hit tests that well in as3 This is what I have:
if (you.Target.hitTestObject(PEnemy.spawn.enemy.hit));
But it is not working
I also get this in output:
TypeError: Error #2007: Parameter hitTestObject must be non-null.
at flash.display::DisplayObject/_hitTest()
at flash.display::DisplayObject/hitTestObject()
at eugenehoudin5AS3_fla::MainTimeline/EnterFrame()
The code cannot target an object that doesn't exist, so you need to put in conditional logic to check if the object is null or not. One thing you could also do to make sure the object always exists for the code is to have it present in all frames, but make it invisible in frames where you do not want it to be seen. Then in your code you could test its visible property before trying to do the hit test - if it is invisible, skip the hit test.
Copy link to clipboard
Copied
If hit only exists in certain frames, then chances are it is a missing object when that code tries to find it. Put a trace in before that line so that you can see where in the chain the null comes to be.
Copy link to clipboard
Copied
Yea the hit can only exist in certain frames so how would I do that code wise
Copy link to clipboard
Copied
The code cannot target an object that doesn't exist, so you need to put in conditional logic to check if the object is null or not. One thing you could also do to make sure the object always exists for the code is to have it present in all frames, but make it invisible in frames where you do not want it to be seen. Then in your code you could test its visible property before trying to do the hit test - if it is invisible, skip the hit test.
Copy link to clipboard
Copied
Ye I just tested if it was not null then hit test and it works thanks.
So in as3 unlike as2 if somethings not there you need to stop the code from executing with a if(!null) statement are something like that ?
Copy link to clipboard
Copied
The difference between AS2 and AS3 as far as code failing is that AS3 is very good about telling you when there is a problem, often pointing directly yo it.... AS2 more often leaves you wondering why nothing works without a hint that there is a problem with the code.
Copy link to clipboard
Copied
Ye Totally working now
Find more inspiration, events, and resources on the new Adobe Community
Explore Now