Skip to main content
Inspiring
November 24, 2015
Answered

if(contains) & removeChild problems

  • November 24, 2015
  • 1 reply
  • 448 views

so i want to make it whenever evilShadow touches charShadow, dark is added. the whole function is an enter frame function.  and whenever evilshadow does not touch charShadow there shouldnt be any dark.

if(evilShadow.hitTestObject(charShadow))

  {

  if(fadePresent == false)

  {

  dark = new DarkFade;

  dark.scaleX = 4;

  dark.scaleY = 4;

  addChild(dark);

  fadePresent = true;

  }

  }

  if((evilShadow.hitTestObject(charShadow)==false)&&(contains(dark)))

  {

     fadePresent = false;

  removeChild(dark);

  }

everythin works fine but this error shows up

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

  at flash.display::DisplayObjectContainer/contains()

  at HorrorGame/checkforHits()

This topic has been closed for replies.
Correct answer somebeginner

i fixed the errors with another variable

i took out if(contains(dark)) to if(darkhere == true)

darkhere boolean tells if dark is present on the screen.  idk why contains doesnt work tho

1 reply

kglad
Community Expert
Community Expert
November 24, 2015

use:

if(evilShadow.hitTestObject(charShadow))

  {

  if(!dark||!dark.stage)

  {

  dark = new DarkFade();

  dark.scaleX = 4;

  dark.scaleY = 4;

  addChild(dark);

  }

  }

  if(!evilShadow.hitTestObject(charShadow)&&dark&dark.stage)

  {

  removeChild(dark);

  }

Inspiring
November 30, 2015

i put in ur codes and i get this

1067: Implicit coercion of a value of type DarkFade to an unrelated type Number.

1067: Implicit coercion of a value of type flash.display:Stage to an unrelated type Number.

from

if(!evilShadow.hitTestObject(charShadow)&&dark&dark.stage)


what do the exclamation marks do?

somebeginnerAuthorCorrect answer
Inspiring
November 30, 2015

i fixed the errors with another variable

i took out if(contains(dark)) to if(darkhere == true)

darkhere boolean tells if dark is present on the screen.  idk why contains doesnt work tho