1 Reply Latest reply on May 2, 2007 12:27 PM by robsharma1985

    One button Hide/Show

    ichabodBcrane Level 1
      I have the following code ready and working for a hide/show function. What is the easiest way to turn this into a ONE button function rather than the 2 that I have it at?

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

      <mx:Script>

      <![CDATA[
      import mx.controls.Button;


      private function showTab( event:MouseEvent ):void
      {
      var button:Button = Button( event.target );
      button.enabled = false;

      var hideButton:Button = Button( button.parent.getChildAt( 1 ) );
      hideButton.enabled = true;

      switch( button.label )
      {

      case "Show Legend" : legendBox.addChildAt( vBox0, 0 );

      break;

      }
      }

      private function hideTab( event:MouseEvent ):void
      {
      var button:Button = Button( event.target );
      button.enabled = true;

      var showButton:Button = Button( button.parent.getChildAt( 0 ) );
      showButton.enabled = true;

      switch( button.label )
      {
      case "Hide Legend" : legendBox.removeChild( vBox0 );
      break;

      }
      }
      ]]>
      </mx:Script>




      <mx:VBox width="98%" y="100" height="100%" id="legendAndSorter" x="14">

      <mx:HBox>
      <mx:Button label="Show Legend" enabled="false" click="showTab( event );"/>
      <mx:Button label="Hide Legend" click="hideTab( event );"/>
      </mx:HBox>


      <mx:VBox id="legendBox" x="10">
      <mx:VBox id="vBox0">
      <mx:Legend id="legend1" fontSize="8">
      <mx:LegendItem fontWeight="normal" markerHeight="5" markerWidth="5" label="Test" fill="0x000FF00" styleName="legend" />
      <mx:LegendItem fontWeight="normal" markerHeight="5" markerWidth="5" label="Test 2" fill="0xFF0000" styleName="legend"/>
      <mx:LegendItem fontWeight="normal" markerHeight="5" markerWidth="5" label="Test 3" fill="0x663300" styleName="legend"/>
      <mx:LegendItem fontWeight="normal" markerHeight="5" markerWidth="5" label="Test 4" fill="0x000099" styleName="legend"/>
      </mx:Legend>

      </mx:VBox>
      </mx:VBox>



      </mx:VBox>


      </mx:Application>



      Thanks