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 8957787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:04:15+00:00 2026-06-15T15:04:15+00:00

I am working on a flash game that requires me to instantiate objects from

  • 0

I am working on a flash game that requires me to instantiate objects from a class into the scene at runtime and and delete these objects through code.
This works fine and i can dynamically add and remove instances from the game, however after about two minutes in it starts lagging extremely and will eventually crash alltogether.

I used numchildren() to trace how many objects are in the scene and it appears that some of the instances aren’t being deleted properly because the number traced will increase and eventually reach near 2000 objects…

I am using removeChild() to delete the objects and am trying to figure out why these objects are still in the scene.
I read somewhere that objects may still use cpu if they haven’t properly been reset.

I am still new to working in flash and my main question is – how do I find out which objects aren’t being deleted and how do I remove them entirely from the game?

What else do I need to add to the code other than the simple removeChild() part?
Any help would be greatly 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-15T15:04:16+00:00Added an answer on June 15, 2026 at 3:04 pm

    Please provide the code part where removeChild() method is used.

    Generally you should use removeChild() this way:

    import flash.display.MovieClip;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    
    var movieClip:MovieClip;
    var timer:Timer=new Timer(5000, 1);
    timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
    
    makeMovieClips();
    
    function makeMovieClips() {
        for (var i:int; i<2000; i++) {
            movieClip=new MovieClip();
            movieClip.graphics.beginFill(Math.random()*0xFFFFFF);
            movieClip.graphics.drawCircle(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight, Math.random()*40);
            movieClip.graphics.endFill();
            addChild(movieClip);
        }
        trace (numChildren) // should output 2000;
        timer.start();
    }
    
    function onTimerComplete(e:TimerEvent):void {
        while (numChildren>0) {
            movieClip=getChildAt(0) as MovieClip;
            removeChild(movieClip);
            // or we can use removeChildAt(0); instead of 2 lines above
        }
        trace (numChildren) // should output 0, because all objects are removed from display list;
    }
    

    additionally note that removing objects form display list, won’t exclude them from memory, if any references are left on those objects. In my example reference to one MovieClip object remains after all Movieclips are removed from stage, so it will occupy some portion of VM’s memory and Garbage Collector won’t clean that portion. In my example, to remove reference, I should add this line of code after while loop in onTimerComplete method:

    movieClip=null;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Flash game that runs fine when testing through Flash professional,
This is a little snippet from a little flash game I'm working on: This
I'm working on a little flash game that has a couple of GUI components.
I am working on a game in which there are several Plane objects that
I'm working on a small game in Flash (AS3) that generates levels using small
I'm working on a Flash game where there are scenes that display a few
So I'm working on a flash game where I'm using bitmapdata to determine collision
I'm currently working on a flash game and I need to know how to
Salut, I'm currently working on a pool game in flash, using box2d for physics
Hai am trying to load the variables from parent(flash) to child(flash).Its working fine,. parent

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.