Be a Supporter!

[AS3] Bullet impact child issue..

  • 454 Views
  • 7 Replies
New Topic Respond to this Topic
Barzona
Barzona
  • Member since: Jan. 4, 2009
  • Offline.
Forum Stats
Member
Level 12
Game Developer
[AS3] Bullet impact child issue.. May. 19th, 2012 @ 03:03 PM Reply

Here is the current work in progress. Use the mouse to fire arrows at things. You may also move with the "A" and "D" keys.

Okay, I just put this code on the third frame of my "Impact" movie clip's third timeline frame:

stop();
stage.removeChild(this);

and now I am getting this error, despite the fact that the game is running "properly":

TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at Impact/frame3()

I figured it would work and it seems to be doing so, but what is Flash's problem?

I would have tried removing the movie clip in the body code of my document class, but I'm not quite sure how to do that after a certain amount of time (I, of course, want the image to be visible for a short while).

Khronosis
Khronosis
  • Member since: Mar. 28, 2010
  • Offline.
Forum Stats
Member
Level 17
Programmer
Response to [AS3] Bullet impact child issue.. May. 19th, 2012 @ 03:37 PM Reply

At 5/19/12 03:03 PM, Barzona wrote: I would have tried removing the movie clip in the body code of my document class, but I'm not quite sure how to do that after a certain amount of time (I, of course, want the image to be visible for a short while).
if(this.currentFrame == 3)
{
     parent.removeChild(this);
}

I implore you to reconsider.

Barzona
Barzona
  • Member since: Jan. 4, 2009
  • Offline.
Forum Stats
Member
Level 12
Game Developer
Response to [AS3] Bullet impact child issue.. May. 20th, 2012 @ 01:15 AM Reply

At 5/19/12 03:37 PM, Khronosis wrote:
At 5/19/12 03:03 PM, Barzona wrote: I would have tried removing the movie clip in the body code of my document class, but I'm not quite sure how to do that after a certain amount of time (I, of course, want the image to be visible for a short while).
if(this.currentFrame == 3)
{
parent.removeChild(this);
}

I tried your code (assuming on the impact object's timeline) and it did the same thing; worked, but got an error.

stretch1one
stretch1one
  • Member since: Jul. 9, 2004
  • Offline.
Forum Stats
Member
Level 08
Artist
Response to [AS3] Bullet impact child issue.. May. 20th, 2012 @ 08:48 AM Reply

Have you tried putting the code in the main timeline?

if(impact.currentFrame == 3)
{
     impact.removeChild(this);
}

and instead of this, the name of the variable you declared. "arrow" or whatever it may be.


BBS Signature
Barzona
Barzona
  • Member since: Jan. 4, 2009
  • Offline.
Forum Stats
Member
Level 12
Game Developer
Response to [AS3] Bullet impact child issue.. May. 20th, 2012 @ 09:30 AM Reply

At 5/20/12 08:48 AM, stretch1one wrote: Have you tried putting the code in the main timeline?

if(impact.currentFrame == 3)
{
impact.removeChild(this);
}

and instead of this, the name of the variable you declared. "arrow" or whatever it may be.

:(
No dice.

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to [AS3] Bullet impact child issue.. May. 20th, 2012 @ 11:54 AM Reply

The purpose of frames is to do animation.

If you want to get rid of an Object after a certain amount of time, use a Timer.

Khronosis
Khronosis
  • Member since: Mar. 28, 2010
  • Offline.
Forum Stats
Member
Level 17
Programmer
Response to [AS3] Bullet impact child issue.. May. 20th, 2012 @ 12:41 PM Reply

At 5/20/12 01:15 AM, Barzona wrote: I tried your code (assuming on the impact object's timeline) and it did the same thing; worked, but got an error.

That code was intended to be placed inside the onEnterFrame event listener in the object's class file, not the timeline.

On that note, you really shouldn't be placing code on the timeline; it defeats the purpose of AS3's benefits.


I implore you to reconsider.

Barzona
Barzona
  • Member since: Jan. 4, 2009
  • Offline.
Forum Stats
Member
Level 12
Game Developer
Response to [AS3] Bullet impact child issue.. May. 21st, 2012 @ 01:45 AM Reply

I agree. I'll give your code a try. :)