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

TypeError: Error #2007: Parameter hitTestObject must be non-null.

Participant ,
Feb 05, 2023 Feb 05, 2023

Copy link to clipboard

Copied

i'm making a game in AS3 in keyframe where there is a movieclip (killer) that has to collide with a child(trail) from the move clip(snake) . I like to call add "_mc" for movieclip and "_ins" for instance. Anyways this is my code

 

stage.addEventListener(Event.ENTER_FRAME, killsnake);
function killsnake(event:Event)
{
if (killer_ins.hitTestObject(snake_ins.children))
{
trace("asnltsatopgameal;ntaetnaen");
}
}

 

it keeps giving me the error. I'm not sure how to solve this without it saying "undefined property blablabla" or the error up top. What's a way I can do this?

 

TOPICS
ActionScript , Code , Error

Views

194

Translate

Translate

Report

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
Community Expert ,
Feb 05, 2023 Feb 05, 2023

Copy link to clipboard

Copied

loop through all snake children and hittest each. ie, use numChildren and getChildAt in your for loop. 

Votes

Translate

Translate

Report

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 ,
Feb 06, 2023 Feb 06, 2023

Copy link to clipboard

Copied

like this?

 

for (var i:uint = 0; i < snake_ins.numChildren; i++)
if (snake_ins.getChildAt(i) is snake)
{
trace("asnltsatopgameal;ntaetnaen");
}

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 06, 2023 Feb 06, 2023

Copy link to clipboard

Copied

no:

 

for(var i:int=0;i<snake_ins.numChildren;i++){

if(killer_ins.hitTestObject(snake_ins.getChildAt(i)){

// do whatever other than remove children.

}

}

 

if you're going to be removing some of the children, loop backward:

 

for(var i:int=snake_ins.numChildren-1, i>=0;i--){

if(killer_ins.hitTestObject(snake_ins.getChildAt(i)){

// do whatever

}

}

 

p.s. your instance naming convention precludes more than one instance.  it would be better to use a different convention. eg, killer_1, killer_2, etc 

Votes

Translate

Translate

Report

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 ,
Feb 11, 2023 Feb 11, 2023

Copy link to clipboard

Copied

what naming convention should i use? I can't make the movieclip,instance and linkage all the same

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 11, 2023 Feb 11, 2023

Copy link to clipboard

Copied

LATEST

i made a suggestion already for stage instances.

 

for linkage id's using a name+"_id" works.

Votes

Translate

Translate

Report

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