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

if(contains) & removeChild problems

Explorer ,
Nov 24, 2015 Nov 24, 2015

Copy link to clipboard

Copied

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

Views

362

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

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

Votes

Translate

Translate
Community Expert ,
Nov 24, 2015 Nov 24, 2015

Copy link to clipboard

Copied

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

  }

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

the ! is a negation (or not) operator.

there's a typo.  that should be

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

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