Flex: Method doesn't work when being called on parentDocument

Posted by ChrisInCambo on Stack Overflow See other posts from Stack Overflow or by ChrisInCambo
Published on 2010-05-08T16:54:07Z Indexed on 2010/05/08 16:58 UTC
Read the original article Hit count: 238

Filed under:

Hi,

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 {
        myAccordion.removeChild(myAccordion.selectedChild);
      }

    ]]>

  </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 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.

Cheers,

Chris

© Stack Overflow or respective owner

Related posts about flex