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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:41:06+00:00 2026-06-07T11:41:06+00:00

I wrote a AS3 class to make a Counter function. Click and hold mouse

  • 0

I wrote a AS3 class to make a Counter function. Click and hold mouse in blue area to define a value. I try to show a indicator picture to users that reminding the variation.

But when I drag mouse a little quick in the blue area a error will occur:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display::DisplayObjectContainer/removeChild()
    at test/get2()

I have read some similar issue posts, but I can’t fix this. Could you give me any help? Thank you!

Download .fla and .as in CS6

Download .fla and .as in CS5

The code is below:

package  {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.text.TextFormat;
    import flash.events.Event;

    public class test extends Sprite{
        var i:int=20; //Set a var for the number displayed in stage.
        var mx1:Number; //Set a var to save MouseY when MOUSE_DOWN
        var mx2:Number; //Set a var to save MouseY when MOUSE_UP
        var num:int=0; //Set a var to calculate result
        var sub1:subbar1=new subbar1();
        var sub2:subbar2=new subbar2();
        var sub3:subbar3=new subbar3();
        var add1:addbar1=new addbar1();
        var add2:addbar2=new addbar2();
        var add3:addbar3=new addbar3();

        public function test() {
            init1(); //Set TextField and addEventListener
            initbar(); //Set indicator picture position when drag mouse
        }

        private function init1():void{
            label=new TextField();
            label.text=String(i);
            label.width=280;
            label.selectable=false;
            label.x=140;
            label.y=90;
            addChild(label);
            Controler.addEventListener(MouseEvent.MOUSE_DOWN,get1); //addEventListener to bluearea
        }

        private function initbar(){
            sub1.x=sub2.x=sub3.x=add1.x=add2.x=add3.x=30;
            sub1.y=35;
            sub2.y=55;
            add3.y=sub3.y=75;
            add2.y=95;
            add1.y=115;
        }

        private function get1(evt:MouseEvent):void{
            mx1=mouseY;
            trace(mx1);
            Controler.removeEventListener(MouseEvent.MOUSE_DOWN,get1);
            stage.addEventListener(MouseEvent.MOUSE_UP,get2); //addEventListener to MOUSE_UP
            stage.addEventListener(Event.ENTER_FRAME,lifebar); //add ENTER_FRAME to display indicator picture when move mouse
        }

        private function get2(evt:MouseEvent):void{
            mx2=mouseY;
            trace(mx2);
            if(mx2<=135&&mx2>=35&&mouseX<=130&&mouseX>=50){ //Limited enable area as the blue area
                if(num>=4){ //Set i value depends on num
                    i=i-3;
                }else if(num<=-4){
                    i=i+3;
                }else{
                    i=i-num;
                }
                label.text=String(i);
            }
            if(num==1){ //remove indicator picture when MOUSE_UP
                removeChild(sub1);
            }
            if(num==2){
                removeChild(sub1);
                removeChild(sub2);
            }
            if(num>=3){
                removeChild(sub1);
                removeChild(sub2);
                removeChild(sub3);
            }
            if(num==-1){
                removeChild(add1);
            }
            if(num==-2){
                removeChild(add1);
                removeChild(add2);
            }
            if(num<=-3){
                removeChild(add1);
                removeChild(add2);
                removeChild(add3);
            }
            stage.removeEventListener(MouseEvent.MOUSE_UP,get2);
            Controler.addEventListener(MouseEvent.MOUSE_DOWN,get1);
            stage.removeEventListener(Event.ENTER_FRAME,lifebar);
        }

        private function lifebar(evt:Event):void{ //Set a ENTER_FRAME to display indicator picture
            num=(mouseY-mx1)/12+1;
            trace(num);
            if(mouseY!=mx1&&num==1){
                addChild(sub1);

            }
            if(num==2){
                addChild(sub2);
            }
            if(num==3){
                addChild(sub3);
            }
            if(num==-1){
                addChild(add1);
            }
            if(num==-2){
                addChild(add2);
            }
            if(num==-3){
                addChild(add3);
            }

        }

    }

}
  • 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-07T11:41:07+00:00Added an answer on June 7, 2026 at 11:41 am

    You are attempting to remove display objects that have not yet been added as a child to the display list.

    Even though sub1 has been instantiated, it has not been added at the time you attempt to remove it:

    child

    Before calling removeChild(obj) on the display object, first test if it has been added as a child by evaluating whether if(contains(obj)) is true.

    At line 67 in test.as, you should perform condition testing to see if sub1 has been added to the display list:

    if(num==1) {
        if(contains(sub1)) // test to see if sub1 is on the display list
            removeChild(sub1);
    }
    

    If this issue continues with other children, you should add additional testing in blocks like these:

    if(num==2){
        removeChild(sub1);
        removeChild(sub2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a Scale9Bitmap class in AS3 and it requires the dev to set
I want to make AS3 top-down racing game. I wrote core code, but now
I have been busy building the UI for a class file I wrote a
Previously I wrote on trying to convert some AS2 to AS3. It's a sliding
I'm having quite some trouble to try and get an app I wrote in
I need to write an AS3 program to search for a certain keyword in
Hey guys I'm not sure how to write this in AS3, but basically I
Wrote a quick Java proggy to spawn 10 threads with each priority and calculate
I wrote a symfony task to fill a database of sample data. Here's a
I wrote a process explorer using C with GUI interface. I want to add

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.