2 Replies Latest reply on Dec 1, 2006 12:25 PM by nasamikey

    Chaning forms via states

    nasamikey
      I want display a new form on the right side of my hdividebox when the tree list node on the left side of my hdividebox is selected. I believe the best way to do this is with states.

      public function formChanged(event:Event):void {
      selectedNode=Tree(event.target).selectedItem;

      This will give me the selected item. Where do I (in the tree list) tell the selecteditme to display the form?
        • 1. Re: Chaning forms via states
          ur_dtrain Level 1
          To the mx:Tree component add itemClick="formChanged()", if you don't already have it.

          Within your function you change the state to show the form (if not already visible):
          this.currentState="formView"

          Now as far as passing the data to your form, you can either assign the data from the selected Item on a piece by piece basis:

          formNameField.text = selectedNode.fname; etc...

          Or embed a setData() function within your form that you simply pass the item to (you still do the one-to-one assignment, but in this function that 'lives' inside the form).

          You can add a test in the itemClick to filter items that don't have data, or should be ignored, then clear the form, or hide it using a state change:

          currentState = "";
          • 2. Re: Chaning forms via states
            nasamikey Level 1
            thanks for the help. One more question.

            public function formChanged(event:Event):void {
            selectedNode=Tree(event.target).selectedItem;

            my form is <mx:State name="Users"> so this.currentState="formView" will refer to this form and
            formNameField.text = selectedNode.fname; = "Users" I believe would be correct. I am just starting to use Flex and this is a test project to get up to speed with the interface and Flex.