Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Simple Hit test

Participant ,
Mar 26, 2013 Mar 26, 2013

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()

TOPICS
ActionScript
788
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 26, 2013 Mar 26, 2013

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.

Translate
LEGEND ,
Mar 26, 2013 Mar 26, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 26, 2013 Mar 26, 2013

Yea the hit can only exist in certain frames so how would I do that code wise

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 26, 2013 Mar 26, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 26, 2013 Mar 26, 2013

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 ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 26, 2013 Mar 26, 2013
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 26, 2013 Mar 26, 2013

Ye Totally working now

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines