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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:34:29+00:00 2026-05-23T22:34:29+00:00

So I was creating a small project for fun last night that involves creating

  • 0

So I was creating a small project for fun last night that involves creating a lot of little circles (star). So to represent this star, I created a star class. Here it is with the most relevant methods

public class Star extends MovieClip
{

public function Star(r:Number)
        {
            starRadius = r;
            this.animated = false;
            this.graphics.beginFill(0xFFFFFF);
            this.graphics.drawCircle(0,0,starRadius);
            this.graphics.endFill();

            this.addEventListener(Event.REMOVED, onRemoval);
        }
public function animate():void
        {
            if( isNull(angle)|| isNull(speed)){
                throw new Error("Angle or speed is NaN. Failed to animate");
            }
            if(animated){
                throw new Error("Star already animated");
            }
            if(this.parent == null){
                throw new Error("Star has not been added to stage yet");
            }

            this.addEventListener(Event.ENTER_FRAME, doAnimate, false, 0);
            animated = true;
        }

private function doAnimate(e:Event):void{

            if(isNull(cachedDirectionalSpeedX) || isNull(cachedDirectionalSpeedY)){
                cachedDirectionalSpeedY = -speed * Math.sin(angle); 
                cachedDirectionalSpeedX = speed * Math.cos(angle);
            }

            this.x += cachedDirectionalSpeedX;
            this.y += cachedDirectionalSpeedY;


            if(this.x > this.parent.stage.stageWidth || this.y > this.parent.stage.stageHeight){
                this.dispatchEvent(new Event("RemoveStar",true));
                this.removeEventListener(Event.ENTER_FRAME, doAnimate);

            }


        }

To give you a summary on what it does, basically on initialization it adds to itself a listener which basically just nulls every instance varialbles. When animate() is called, it adds a listener to itself that animates to a certain direction. This listener also checks whether its location is already outside the stage and stops its movement when it already is. Additionall, it will dispatch an event so that the parent will know when to remove it.

So in the “main” class, I have

this.addEventListener("RemoveStar", removeStar);

and

private function removeStar(e:Event):void
        {
            starCount--;
            this.removeChild(Star(e.target));
        }

I have another listener that basically prints out the number children that it has everytime, but I am not gonna put the code here. THe problem that I have is that… it looks like the listener that removes the star does not work “all the time”. When create 1000 stars during start up and nothing else, the number of children goes down at the very beginning and it gets stuck at a certain number which leads me to think that there are some movie clips do not get removed. Does anyone know what is happening here?

  • 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-23T22:34:30+00:00Added an answer on May 23, 2026 at 10:34 pm

    Check whether you are removing all event listeners, removeStar for instance… I don’t see how you attach the removeStar listener to “Main” yet the remove star function correctly references the e.target property to be a star…

    Basically, you need to “kill” all references to the object for it to be “released” sometime in the future when the GC does it’s pass.

    The reason though you are not “removing” all the stars is probably that only right and bottom edge are checked in your “remove check” code… probably some stars go left or up… add additional conditionals for left and up and it might fix itself… (this.x < 0 || this.y < 0)

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

Sidebar

Related Questions

So I'm working on a small project that involved creating a camera class with
I am creating a small modal form that is used in Winforms application. It
I am creating a small application that will be deployed on Window. The database
I'm creating a small app in ASP.NET MVC that generates ics (iCal) files based
I am creating a small console app that needs a progress bar. Something like...
I'm creating a small application on an embedded device that has a boa web
I am looking at creating a small class generator for a project. I have
I'm working on a small Java project that now connects to a MS SQL
Hello i am creating a small webpage that give our users an interface to
I'm creating a small project which will manipulate some internal components of the project(big

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.