Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8130265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:38:58+00:00 2026-06-06T08:38:58+00:00

Ok, so I’ve been stuck on this for about three hours now and I

  • 0

Ok, so I’ve been stuck on this for about three hours now and I finally feel like asking for help.

Basically, I am trying to remove all instances of an enemy object from the screen when my player ship makes contact with one of them, as he then loses a life and is put back into a safe position on the screen.

EDIT: This is all the code from my Enemy Dude .as file, a bit overboard maybe but nonetheless.

package
{
    import flash.display.MovieClip;
    import flash.events.*;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    public class Enemydude extends MovieClip
    {
        private var _root:Object;
        private var speed:int = 6;
        private var shipps = this
        public function Enemydude()
        {
            addEventListener(Event.ADDED, beginclass);
            addEventListener(Event.ENTER_FRAME, entFrame);
        }

        private function beginclass(event:Event):void
        {
            _root = MovieClip(root);
        }

        private function entFrame(event:Event):void
        {
            x -= speed;
            if(this.x < -64)
            {
                removeEventListener(Event.ENTER_FRAME, entFrame);
                _root.removeChild(this)
            }
            if(_root.gameover)
            {
                x = -700
                removeEventListener(Event.ENTER_FRAME, entFrame);
                removeEventListener(Event.ADDED, beginclass);
            }
            for (var i:int = 0; i<_root.playerBulletContainer.numChildren; i++)
            {
                var bulletTarget:MovieClip = _root.playerBulletContainer.getChildAt(i)
                if (hitTestObject(bulletTarget))
                {
                    removeEventListener(Event.ENTER_FRAME, entFrame);
                    _root.removeChild(this);
                    _root.playerBulletContainer.removeChild(bulletTarget);
                    bulletTarget.removeListeners();
                    _root.Score += 10
                    makeExplosion();
                }
            }
            if(hitTestObject(_root.mcship))
            {
                makeExplosion();
                shipPos();
                removethis();
            }

        }
        private function makeExplosion() 
        {
            var sndExplode:snd_explosion1;
            var sndExplodeChannel:SoundChannel;
            sndExplode=new snd_explosion1();
            sndExplodeChannel=sndExplode.play();
            var newExplosion01:explosionEffect=new explosionEffect  ;
            newExplosion01.x=this.x;
            newExplosion01.y=this.y;
            _root.explosionContainer.addChild(newExplosion01);

        }
        private function shipPos()
        {
            _root.lives -= 1;
            _root.mcship.x = 80;
            _root.mcship.y = 225;
            for each(var i:Enemydude in _root.enemies)
        {
            removethis();
        }

        _root.enemies.length = 0;
        }
        public function removethis():void
        {
            if(parent) parent.removeChild(this)
            removeEventListener(Event.ENTER_FRAME, entFrame);
        }
    }
}

EDIT: And this is the code I now have that relates to the Enemydude in my main timeline, quite sorry about all this.

var enemies:Array = [];
var Shipheight:Number = 300;
var Enemytime:int = 0;
var Enemylimit:int = 16;

    if (Enemytime<Enemylimit)
        {
            Enemytime ++;
        }
        else
        {
            var newEnemy01 = new Enemydude();
            newEnemy01.y = Shipheight;
            newEnemy01.x = stage.stageWidth + 64;
            addChild(newEnemy01);
            enemies.push(newEnemy01);
            Enemytime = 0

function shipY(event:Event):void
{
    Shipheight = Math.ceil(Math.random()* 250) + 80;
}

Thank you for your help in advance, any advice is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:39:00+00:00Added an answer on June 6, 2026 at 8:39 am

    I suggest storing your enemies in an Array.

    For example, create the array enemies:

    var enemies:Array = [];
    

    And then amend your code to:

    else
    {
        var newEnemy01 = new Enemydude();
    
        newEnemy01.y = Shipheight;
        newEnemy01.x = stage.stageWidth + 64;
    
        addChild(newEnemy01); 
        enemies.push(newEnemy01);
    
        Enemytime = 0;
    }
    

    That way you can remove all of the enemies using this new array:

    for each(var i:Enemydude in enemies)
    {
        i.remove(); // Or whatever function Enemydude has to remove itself.
    }
    
    // Empty the enemies Array.
    enemies.length = 0;
    

    Here’s the .remove() method you could make for Enemydude:

    public function remove():void
    {
        if(parent) parent.removeChild(this);
    
        // Remove any event listeners etc from this object.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.