6 Replies Latest reply on Mar 28, 2011 5:45 PM by Gaml-for-flex

    Problems removingChild

    Gaml-for-flex

      I can't seem to remove a named child from my accordian. It adds the child alright and it throws up the alert 'subtracted' the second time the button is clicked which means the if else is okay. Can anyone take a look and see if they can spot anything? Here's the stripped down code:

       

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

         xmlns:s="library://ns.adobe.com/flex/spark"

         xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="955" minHeight="600"

         xmlns:px="library://ns.adobe.com/flex/mx">

       

       

      <fx:Script>

      <![CDATA[

      [Bindable]

      public var colorPick:Array=['0xF6F6F6','0x000000', '0xFF0000', '0xFF8800',

      '0xFFFF00', '0x88FF00', '0x00FF00', '0x00FF88', '0x00FFFF'];

       

      /* Import HBox class. */

      import mx.containers.Accordion;

      import mx.containers.HBox;

      import mx.containers.VBox;

      import mx.controls.TextArea;

      import mx.controls.Alert;

       

       

       

      public function Details():void {

      /* Create new HBox container. */

      if (namebtn.label == "+ Name") {

      Alert.show('added')

      var newHB:HBox = new HBox();

      var text:TextArea = new TextArea();

      newHB.label="Name" ;

      text.text = "name contents";

      namebtn.label = "- Name";

      myAcc.addChild(newHB);

      newHB.addChild(text);

      }

      else {

      Alert.show('subtracted')

      myAcc.removeChild(newHB);

      newHB.removeChild(text);

      namebtn.label = "+ Name";

      }

      }

       

      ]]>

      </fx:Script>

       

      <px:Accordion id="myAcc" height="179" width="257" contentBackgroundAlpha="0.5">

      <px:HBox label="Initial HBox"/>

      </px:Accordion>

       

      <px:Button id="namebtn" label="+ Name" click="Details()" />

       

       

       

      </s:Application>