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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:23:26+00:00 2026-05-15T00:23:26+00:00

In one frame of my fla file (let’s call it frame 2), I load

  • 0

In one frame of my fla file (let’s call it frame 2), I load a few xml files, then send that data into a class that is initialized in that frame, this class creates a few timers and listeners.

Then when this class is done doing it’s work. I call a dispatchEvent and move to frame 3. This frame does some things as well, it’s initialized and creates a few event listeners and timers. When it’s done, I move to frame 2 again.

This is supposed to repeat as often as I need so I need to clean up the references correctly and I’m wondering if I’m doing it correctly.

For sprites I do this.

world.removeChild(Background); // world is the parent stage
Background = null;

For instances of other classes I do this.

Players[i].cleanUp(world); // do any cleanup within the instanced class
world.removeChild(PlayersSelect[i]);

For event listeners I do this.

if(Background != null)
{
    Background.removeEventListener(MouseEvent.CLICK, deSelectPlayer);
}

For timers I do this.

if(Timeout != null)
{
    Timeout.stop();
    Timeout.removeEventListener(TimerEvent.TIMER, queueHandler);
    Timeout.removeEventListener(TimerEvent.TIMER_COMPLETE, queueCompleted);
    Timeout = null;
}

And for library images I do this

if(_libImage!= null)
{
    s.removeChild(Images._libImage); // s is the stage
    _libImage= null;
}

And for the class itself in the main timeline, I do this

Frame2.removeEventListener("Done", IAmDone);
Frame2.cleanUp(); // the cleanup() does all the stuff above
Frame2= null;

Even if I do all this, when I get to frame 2 for the 2nd time, it runs for 1-2 seconds and then I get a lot of null reference errors because the cleanup function is called prematurely.

Am I doing the cleanup correctly?

What can cause events to fire prematurely?

  • 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-05-15T00:23:26+00:00Added an answer on May 15, 2026 at 12:23 am

    For me, the biggest concern is cleaning up listeners, which you are doing. To avoid any errors in listener cleanup, I always check if the item exists, and then if it has the listener; thus:

    if(item)
    {
       if(item.hasEventListener(MouseEvent.CLICK))
       {
          item.removeEventListener(MouseEvent.CLICK,doSomething);
       }
    }
    

    I do a simimlar check before removing child:

    if(item)
    {
       if(this.contains(item))
       {
          this.removeChild(item);
          item.destroy()//or whatever you code is to clear that element of its own dependencies.
          item = null;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created an AS3 preloader, and placed the code for that on frame one.
I have a MovieClip symbol created with flash in a fla file library. There
We're working on a Flash CS4 project where the main .fla file has ballooned
I am making a fighting game in Flash and while I have everything running,
I'm fairly deep with Flash CS4 project. I've got Flex Builder now, and I
I'm trying to make the code below reusable. I need multiple toggle buttons in
This problem is probably very simple to solve but it is not clear to
I'm going to be as specific and verbose as possible and include some of
Tearing my hair out. I created an as3 class - blah.Foo, which extends MovieClip.

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.