Deleting array objects?

just a simple questin that i have yet to figure out. i feel close, but run into problem of it not working.
but i have an array of bullets, or could even be enemies, sand etc

private var _bullet:Array<Bullet>;
private function setupBullet():Void{
    // TODO: maybe put in bullet spawn here instead. easier to have collision and deletion
    _bullet = [];
    var bullets:Bullet = new Bullet();
    bullets.x = _player.x + 32;
    bullets.y = _player.y + 12;
    addChild(bullets);
    _bullet.push(bullets);

    if (bullets.x >= 500) {
      removeChild(bullets);
      _bullet.remove(bullets);
    }
  }

and whilst the creation is absolutely fine. it creates bodies through keyDown and using update. but do want a bullet/sand/enemy to be able to delete/remove itself either from being touched by something else, or by reaching the end of the screen. the bottom of the code posted is what i got to before i had to call a friend and ask about it

many thanks if you can help :wink:

You need to create an update function called at every frame.

In your main add:

addEventListener(Event.ENTER_FRAME, update);

and then create the update function:

function update (event:Event) : Void
{
  for (bullets in _bullet)
  {
    if (bullets.x >= 500)
    {
      removeChild(bullets);
      _bullet.remove(bullets);
    }
  }
}

ooooh. thank you very much. thought i tried something like that before. but will try again

thanks again :wink:

actually. yeah i did try it before some moons ago, but ran into this message

Called from state/PlayState.hx line 102
Uncaught exception - Invalid field access : length

which i have not set a number of enemies, because they are being spawned with a timer every 1 second [though that is to change

most likely the array is null, be sure to create it in the main function of your application, or add a guard in the update function:

if (_bullet != null)
{
  for (bullets in _bullet)
  {
    if (bullets.x >= 500)
    {
      removeChild(bullets);
      _bullet.remove(bullets);
    }
  }
}

oooh. alright. ill give that a bash.

thanks again :wink:

EDIT
AWESOME BALLS. works now. still can see that i really need to not do other work and just be on haxe/openfl :wink:
even a few days away makes it looks like greek :wink:

that does work. up to a certain degree. but istead of removing all the bullets. it only removes the last one shot, not each one.
weird