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

  • SEARCH
  • Home
  • 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 9160213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:41:04+00:00 2026-06-17T13:41:04+00:00

I have the following error: ArgumentError: Error #2025: The supplied DisplayObject must be a

  • 0

I have the following error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at lamagame_fla::MainTimeline/bulletEnterFrame()[lamagame_fla.MainTimeline::frame2:116]

In the following code: Main Timeline

    var j:int;
    addEventListener(Event.ENTER_FRAME, enemyhit);
    function enemyhit(event:Event):void {
    for (i = enemy_array.length -1; i >= 0; i--){
        for(var j = 0; j < bulletarray.length; j++) {       
            if(enemy_array[i].hitTestObject(bulletarray[j])) {
                removeChild(enemy_array[i]);
            removeChild(bulletarray[j]);
            enemy_array.splice(j, 1);
            bulletarray.splice(i, 1);
            j--;
            break;
            }
        }

        }
    }
stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown)
stage.addEventListener(MouseEvent.MOUSE_UP, onUp)

var pressedState:int = 0;

var myTimer:Timer = new Timer(10);
myTimer.addEventListener(TimerEvent.TIMER, onTimerTick);

function onDown(e:MouseEvent)
{
    myTimer.start();
    switch(e.currentTarget)
    {
        case stage:
        pressedState = 1;
        break;
    }
}

function onUp(e:MouseEvent)
{
    myTimer.stop();
    pressedState = 0
}

function onTimerTick(e:TimerEvent)
{
    switch(pressedState)
    {
        case 1:
        // Create a new bullet
    var b:Bullet = new Bullet();
    // Set his position to the tank position
        if(llama.scaleX==1) {
    b.x = llama.x+20;
    b.y = llama.y-50;
    }else{
        if(llama.scaleX==-1) {
    b.x = llama.x-25;
    b.y = llama.y-50;
    }else{
        b.x = llama.x+20;
        b.y = llama.y-50;
    }
    }
    // Save the randian angle between the mouse and the tank
    // This angle will set the direction of the bullet
    b.angleRadian = Math.atan2(mouseY - llama.y,mouseX - llama.x);
    // Add an enter frame event on each bullet
    b.addEventListener(Event.ENTER_FRAME, bulletEnterFrame);
    // Add this display object on the display list
    addChild(b);
    bulletarray.push(b);
        break;
    }
    return b;
}
import flash.display.MovieClip;
import flash.geom.Point;
import flash.events.MouseEvent;

// Code by Benoit Freslon.
// Tutorials, Flash games:
// http://www.benoitfreslon.com

// This object will always look at the mouse cursor
llama.head.addEventListener(Event.ENTER_FRAME,  llamaenterframe);
// This function will be launched every frame (25 times by seconds);
function llamaenterframe(pEvt) {
    // pEvt.currentTarget: myTank
    var b = pEvt.currentTarget;
    // Get the radian angle between the tank and the cursor
    // You can also replace mouseX and mouseY by another coordinates
    // Convert the radian angle in dedree angle
    var angleDegree = b.angleRadian * 90 / Math.PI;
    // Set the orientation
    b.rotation = angleDegree;
    // Display angle of rotation in degree
    vcam.txtAngle.text = Math.round(angleDegree) + "°";
}
// Velocity of each bullet
var speed = 8;

function bulletEnterFrame(pEvent) {
    // Get the current object (Bullet)
    var b = pEvent.currentTarget;
    // Move this bullet on each frames
    // On X axis use the cosinus angle
    b.x +=  Math.cos(b.angleRadian) * speed;
    // On Y axis use the sinus angle
    b.y +=  Math.sin(b.angleRadian) * speed;
    // Orient the bullet to the direction
    b.rotation = b.angleRadian * 180 / Math.PI;
    // You have to remove each created bullet
    // So after every moves you must check bullet position
    // If the bullet is out of the screen
    if (!b.hitTestObject(vcam)) {
        // Remove it from the display list
        removeChild(b);
        bulletarray.splice(bulletarray.indexOf(j), 1);
        // /!\ AND REOMOVE HIS EVENT LISTER
        b.removeEventListener(Event.ENTER_FRAME, bulletEnterFrame);
    }
}

// Set his position to the tank position

var maxHP:int = 400;
var currentHP:int = maxHP;
var percentHP:Number = currentHP / maxHP;
updateHealthBar();

function updateHealthBar():void
{
     percentHP = currentHP / maxHP;
     llama.healthBar.barColor.scaleX = percentHP;
}
// properties in class ----------
        var enemy_array:Array = new Array;  

         // dynamically place MovieClip instances on the stage ----------
        // inside Constructor function of class
        var enemy_number:int=100;//number of circles on the stage

        for(var i=0; i<enemy_number; i++) {

            enemy_array[i] = new enemy(); //linkage in the library
            enemy_array[i].x = MovieClip(root).background1tiles.x + Math.floor( Math.random()* MovieClip(root).background1tiles.width) ;
            enemy_array[i].y = MovieClip(root).background1tiles.y + Math.floor( Math.random()* MovieClip(root).background1tiles.height) ;
            enemy_array[i].addEventListener(Event.ENTER_FRAME, function (event:Event):void {
            if(event.currentTarget.hitTestObject(llama)) {
            currentHP -= 1;
            if(currentHP <= 0) //if the player died
            {
            currentHP = 0; //set his HP to zero, (just in case)
            vcam.gotoAndStop(2); //add any extra death-code here
            }
            updateHealthBar(); //update the healthBar   
            }
            });
            addChild(enemy_array[i]);
            enemy_array[i].addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler_4);

function fl_EnterFrameHandler_4(event:Event):void
{
    if(event.currentTarget.hitTestObject(vcam)) {
        if(event.currentTarget.x < Math.floor(llama.x)) {
            event.currentTarget.x+=event.currentTarget.randomspeed;
        }else{
            event.currentTarget.x-=event.currentTarget.randomspeed;
        }
        if(event.currentTarget.y < Math.floor(llama.y)) {
            event.currentTarget.y+=event.currentTarget.randomspeed;
        }else{
            event.currentTarget.y-=event.currentTarget.randomspeed;
        }
    }
}
        }
/* Enter Frame Event
Executes the function fl_EnterFrameHandler_6 defined below each time the playhead moves into a new frame of the timeline.

Instructions:
1. Add your custom code on a new line after the line that says "// Start your custom code" below.
The code will execute when the playhead moves into a new timeline frame.
*/

addEventListener(Event.ENTER_FRAME, basics);

function basics(event:Event):void {
    //Start your custom code
    // This example code displays the words "Entered frame" in the Output panel.
    if(llama.x > 3005.6) {
        llama.x = 3005.6;
    }
    if(llama.x < -2369) {
        llama.x = -2369;
    }
    if(llama.y > 0) {
    llama.y=0;
}
    vcam.x=llama.x;
    vcam.y=llama.y;
    vcam.coordinates.text="Llama's X is "+llama.x+".  And Llama's Y is "+llama.y;
    // End your custom code
}
/* Move with Keyboard Arrows
Allows the specified symbol instance to be moved with the keyboard arrows.

Instructions:
1. To increase or decrease the amount of movement, replace the number 5 below with the number of pixels you want the symbol instance to move with each key press.
Note the number 5 appears four times in the code below.
*/

var upPressed:Boolean = false;
var downPressed:Boolean = false;
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;

stage.addEventListener(Event.ENTER_FRAME, dothelistener);

function dothelistener(event:Event) {
if(vcam.currentFrame==2) {
    removeEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler_11);
    llama.removeEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey);
    stage.removeEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed);
    stage.removeEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed);
}
}

llama.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed);

function fl_MoveInDirectionOfKey(event:Event)
{
    if (upPressed)
    {
        llama.y-=5;
    }
    if (downPressed)
    {
        llama.y+=5;
    }
    if (leftPressed)
    {
        llama.scaleX=-1;
        llama.x-=5;
    }
    if (rightPressed)
    {
        llama.scaleX=1;
        llama.x+=5;
    }
}

function fl_SetKeyPressed(event:KeyboardEvent):void
{
    switch (event.keyCode)
    {
        case Keyboard.UP:
        {
            upPressed = true;
            break;
        }
        case Keyboard.DOWN:
        {
            downPressed = true;
            break;
        }
        case Keyboard.LEFT:
        {
            leftPressed = true;
            break;
        }
        case Keyboard.RIGHT:
        {
            rightPressed = true;
            break;
        }
    }
}

function fl_UnsetKeyPressed(event:KeyboardEvent):void
{
    switch (event.keyCode)
    {
        case Keyboard.UP:
        {
            upPressed = false;
            break;
        }
        case Keyboard.DOWN:
        {
            downPressed = false;
            break;
        }
        case Keyboard.LEFT:
        {
            leftPressed = false;
            break;
        }
        case Keyboard.RIGHT:
        {
            rightPressed = false;
            break;
        }
    }
}
// Velocity of each llama

/* Mouse Click Event
Clicking on the specified symbol instance executes a function in which you can add your own custom code.

Instructions:
1. Add your custom code on a new line after the line that says "// Start your custom code" below.
The code will execute when the symbol instance is clicked.
*/

vcam.magnify.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_10);

function fl_MouseClickHandler_10(event:MouseEvent):void
{
    // Start your custom code
    // This example code displays the words "Mouse clicked" in the Output panel.
    vcam.width-=25;
    vcam.height-=20;
    // End your custom code
}

/* Mouse Click Event
Clicking on the specified symbol instance executes a function in which you can add your own custom code.

Instructions:
1. Add your custom code on a new line after the line that says "// Start your custom code" below.
The code will execute when the symbol instance is clicked.
*/

vcam.magnifyun.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_11);

function fl_MouseClickHandler_11(event:MouseEvent):void
{
    // Start your custom code
    // This example code displays the words "Mouse clicked" in the Output panel.
    vcam.width+=25;
    vcam.height+=20;
    // End your custom code
}
var bulletarray:Array = new Array;
/* Enter Frame Event
Executes the function fl_EnterFrameHandler_10 defined below each time the playhead moves into a new frame of the timeline.

Instructions:
1. Add your custom code on a new line after the line that says "// Start your custom code" below.
The code will execute when the playhead moves into a new timeline frame.
*/

addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler_10);

function fl_EnterFrameHandler_10(event:Event):void
{
    //Start your custom code
    // This example code displays the words "Entered frame" in the Output panel.
    if(vcam.currentFrame == 2) {
        llama.removeEventListener(Event.ENTER_FRAME,  llamaenterframe);
    }
    // End your custom code
}

/* Enter Frame Event
Executes the function fl_EnterFrameHandler_11 defined below each time the playhead moves into a new frame of the timeline.

Instructions:
1. Add your custom code on a new line after the line that says "// Start your custom code" below.
The code will execute when the playhead moves into a new timeline frame.
*/

addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler_11);

function fl_EnterFrameHandler_11(event:Event):void
{
    //Start your custom code
    // This example code displays the words "Entered frame" in the Output panel.
    vcam.count.text = bulletarray.length;
    // End your custom code
}

I tried if(parent) but then only some go through the hittest (only some bullets remove and only sometimes the enemy hp goes down)
The enemy’s hp is configured through an integer(currentHP2)
Any help is appreciated, and thanks.

[EDIT]

After I do if(bulletarray[j].parent) then only some of the bullets work

  • 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-17T13:41:05+00:00Added an answer on June 17, 2026 at 1:41 pm

    removeChild(enemy_array[i]); doesn’t work because you don’t have the context defined, so by default is using the current object, which may be the timeline. think of it as this.removeChild(enemy_array[i]);, where this is timeline.

    The quickest way of fixing it is doing something like the:

     (enemy_array[i] as MovieClip).parent.removeChild(enemy_array[i]);
    

    where you find the object, read it as a movieclip, so that you can access the parent object, on which you can call remove.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use wcsncasecmp inside c/c++ app. Compile have following error: error: 'wcsncasecmp' was not
I have the following error with my ASP.NET web site. I have just moved
I have the following error: LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
I have the following error message: SQLSTATE[HY000] [2003] Can't connect to MySQL server on
I have the following error Exception in thread main javax.naming.NameNotFoundException: CounterBean not bound trying
I have the following error when I try to compile my code in g+
When printing a report, the user sometime have the following error: CrystalDecisions.CrystalReports.Engine.LogOnException: Error in
I'm trying to install memcached-1.2.8-repcached-2.2.1 I have the following error after running make :
After a recent submission I have gotten the following error: Invalid Signature - the
I have following asp.net code but it gives error when I change dropdown selected

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.