Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-29-2012, 02:39 AM   #1
OhAlexO
Cloud Strife's Agent
 
Join Date: Jun 2012
Location: Iowa
Posts: 3
Default removeChild error 2007

First off I'd like to say I did a search on this and although there are many subjects on the matter, none really apply to mine.

My problem is this: There is an enemy on the stage(enemyTwo) in which I remove if its health meter gets below a certain point. You lower the enemy's health by hitting it with little daggers that you throw.

Everything works fine up to a point, the health bar slowly goes down and the enemy even seems to disappear when the removeChild/enemyTwo = null directives are called, however, there seems to be a small window of time where the daggers will hit an invisible version of the enemy which in turn gives me the "Error #2007: Parameter hitTestObject must be non-null" error which in turn causes other things to go awry or Id just ignore it =).


ActionScript Code:
public function checkCollisionWithEnemies(bullet:MovieClip)         {                         if(enemyTwo != null)             {                 if(enemyTwo.hitTestObject(bullet))                 {                     enemyTwo.subObject.meter.width -= 10;                     removeChild(bullet);                                                             if(enemyTwo.subObject.meter.width < 3)                     {                                                 enemyTwo.stop();                         removeChild(enemyTwo);                         enemyTwo = null;                                             }                 }                                             }          }

ActionScript Code:
private function onEnter(evt:Event):void         {                         y -= 10;             rotation += 20;                         MovieClip(parent).checkCollisionWithEnemies(this);                                 }

Any insight would be appreciated.
OhAlexO is offline   Reply With Quote
Old 06-29-2012, 02:44 AM   #2
ASWC
Super Moderator
 
ASWC's Avatar
 
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528
Default

Apparently you can write if statements to check things ... Why don't write one to check if you should remove something?
ActionScript Code:
if(enemyTwo.parent) {     removeChild(enemyTwo); }
__________________
aswebcreations
Super Duper!
ASWC is offline   Reply With Quote
Old 06-29-2012, 03:00 AM   #3
OhAlexO
Cloud Strife's Agent
 
Join Date: Jun 2012
Location: Iowa
Posts: 3
Default

It figures I would find out the solution to my problem shortly after clicking submit(spent the last two days with this bugging the crap out of me).

Anyway, I put an extra if(enemyTwo != null) in front of a hittest between my player and the enemy, it worked. Flash pointed me to one point in the code so I forgot that I should check all references to each variable, and not work in tunnel vision mode.

TL:DR - For anyone with a similar problem, check all references to the variable in question, not just where the program says the problem is.

P.S. I appreciate the attempt to help in the form of an insult, it really encourages me to be more active in the forums. There is a reason I never ask for help on any forum.
OhAlexO is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:12 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.