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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:47:04+00:00 2026-05-14T20:47:04+00:00

I wonder is anyone can look at this code and tell me why calling

  • 0

I wonder is anyone can look at this code and tell me why calling the removeSelectedChild works when called from the same document, but returns the following error when called from the child document/component.

“ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.”

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >

  <mx:Accordion id="myAccordion" 
  width="100%" height="100%"
  selectedIndex="0">

  <mx:Script>
    <![CDATA[

      public function removeSelectedChild():void {
          trace("before");
      try {
              myAccordion.selectedChild.parent.removeChild(myAccordion.selectedChild)
      } catch(err:ReferenceError) {
          trace("catch") 
          }
          trace("after");
      }

    ]]>

  </mx:Script>

  <mx:headerRenderer>
    <mx:Component>
      <mx:Button click="{ parentDocument.removeSelectedChild() }" />
    </mx:Component>
  </mx:headerRenderer>

  <mx:HBox>
    <mx:Button click="{ removeSelectedChild() }" />
  </mx:HBox>

  </mx:Accordion>

</mx:Application>

Clicking on the button in the child produces the expected result, whilst clicking on the header removes the child as expected but also throws an error despite the fact they both call exactly the same method.

Sorry that the example is a little contrived, this problem arose in a quite complicated view, which was using all kinds of custom components. This was the only way I could display it in a way that will be quick for you to compile and easy to focus on the real issue without background noise.

I’m pulling my hair out on this one and would really appreciate it if anyone could help.

UPDATE: I have now discovered that the exception is fired after the method has finished executing. See the trace statements above. “after” is traced before the exception is thrown.

Cheers,

Chris

  • 1 1 Answer
  • 1 View
  • 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-14T20:47:04+00:00Added an answer on May 14, 2026 at 8:47 pm

    As you noted, the error is not being thrown by your function. The default action when clicking on the header of an accordion is to expand or contract that element. Since you’re removing the element, when Flex tries to expand or contract it, you get an error.

    You can fix it by stopping the event from doing its default action:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
    
        <mx:Accordion id="myAccordion" 
                      width="100%" height="100%"
                      selectedIndex="0">
    
            <mx:Script>
                <![CDATA[
    
                    public function removeSelectedChild(event:MouseEvent):void {
                        myAccordion.removeChild(myAccordion.selectedChild);
                        event.stopImmediatePropagation();
                    }
    
                ]]>
    
            </mx:Script>
    
            <mx:headerRenderer>
                <mx:Component>
                    <mx:Button click="{ parentDocument.removeSelectedChild(event) }" />
                </mx:Component>
            </mx:headerRenderer>
    
            <mx:HBox>
                <mx:Button click="{ removeSelectedChild(event) }" />
            </mx:HBox>
    
        </mx:Accordion>
    
    </mx:Application>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a bit of config trouble in Wordpress and wonder if anyone can help.
I wonder if anyone could please help me I have been using HTML tidy
I wonder if anyone knows the flag for gcc to disable tailcall optimizations. Basically
After writing code that can be boiled down to the following: var size=-1; var
I've been playing around with the Liquid templating engine this weekend, and I wonder
We have customers asking for apps that can run on both iPhone and Android.
I wonder where and what I have to edit to make the first column
we've got a problem with one of our non dpi aware MFC applications. If
In my application (Delphi), I need to list all the USB storage devices. These
I'm writing an application. I want various parts of it to be accessible via

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.