2 Replies Latest reply on Jan 12, 2011 7:21 PM by pal..

    Set variable in main mxml based on check box selection in another mxml

    pal..

      I have a two mxml, In one of my mxml I have a checkbox, on checkbox_click event I want to pass some value to my main.mxml.
      Using this value I want to toggle the visibility of map layer in main.mxml.

       

      So far I have declared a bindable boolean variable in my main application mxml.
      And written a function to set the value of this boolean variable depending on some other variable in the second mxml. This second boolean variable is set depending on the checkbox selection in second mxml. now I do not understand from where should I call this function so that everytime checkbox is checked or unchecked value of my bindable boolean variable (declared in main app) changes.

      Is there any other way of doing this?

       

      Thanks in Advance

        • 1. Re: Set variable in main mxml based on check box selection in another mxml
          Gregory Lafrance Level 6

          This makes it even easier:

           

          -------------- MyComp.mxml ----------------

          <?xml version="1.0" encoding="utf-8"?>
          <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
            <mx:Script>
              <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.events.ListEvent;
                [Bindable] public var compBool:Boolean = false;
                
                private function toggleVisibility(evt:ListEvent):void{
                  if(cmbx.selectedLabel == "show"){
                    compBool = true;
                  }else{
                    compBool = false;
                  }
                }
              ]]>
            </mx:Script>
            <mx:ComboBox id="cmbx" dataProvider="{new ArrayCollection(['hide', 'show'])}"
              change="toggleVisibility(event)"/>
          </mx:VBox>
          


          -------------- mainapp.mxml -------------

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            xmlns:comp="*">
            <comp:MyComp id="compObj"/>
            <mx:Label text="Map Component" visible="{compObj.compBool}" includeInLayout="{compObj.compBool}"/>
          </mx:Application>
          


          If this post answers your question or helps, please mark it as such. Thanks!

          http://www.stardustsystems.com
          Adobe Flex Development and Support Services

          1 person found this helpful
          • 2. Re: Set variable in main mxml based on check box selection in another mxml
            pal.. Level 1

            Is there a way to listen checkbox click event from main application?

             

            Thanks..