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

if(contains) & removeChild problems

Explorer ,
Nov 24, 2015 Nov 24, 2015

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

TOPICS
ActionScript
407
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

Explorer , Nov 30, 2015 Nov 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

Translate
Community Expert ,
Nov 24, 2015 Nov 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);

  }

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
Explorer ,
Nov 30, 2015 Nov 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?

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
Explorer ,
Nov 30, 2015 Nov 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

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
Community Expert ,
Nov 30, 2015 Nov 30, 2015
LATEST

the ! is a negation (or not) operator.

there's a typo.  that should be

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

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