4 Replies Latest reply on Mar 26, 2008 10:25 PM by SujitG

    Muiltiple forms + addEventListener not working

    khitlin
      Any know of any issues with defining eventListeners to fields across forms on the same mxml doc? See my code below, the first event handler gets set fine, but any secondary ones do not get set. No compilation errors here?


      <mx:Box
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      width="100%"
      height="100%" paddingTop="5" paddingLeft="5" creationComplete="init()">

      <mx:Script>
      <![CDATA[

      private function init():void{
      //This first event listener gets set but the second one does not...
      Email.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, tabAccordian);
      permCountry.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, tabAccordian);
      Alert.show(Email.tabIndex.toString());
      }

      private function tabAccordian(fEvent:FocusEvent):void{
      //Alert.show(fEvent.currentTarget.toString());
      formAccordion.selectedIndex += 1;
      }

      ]]>
      </mx:Script>

      <mx:Accordion id="formAccordion" width="100%" height="510">
      <mx:Form id="applicantData" label="Personal Information (1-6)" creationComplete="init()" >
      <mx:FormItem label="Last Name">
      <mx:TextInput id="lastName" tabIndex="1"/>
      </mx:FormItem>
      <mx:FormItem label="First Name">
      <mx:TextInput id="firstName" tabIndex="1"/>
      </mx:FormItem>
      <mx:FormItem label="Email">
      <mx:TextInput id="Email" tabIndex="2"/>
      </mx:FormItem>
      </mx:Form>

      <mx:Form id="permAddress" label="Permanent Address (7)" creationComplete="init2()">
      <mx:FormItem label="House or Building #">
      <mx:TextInput id="permHouseNum" width="60" tabIndex="10"/>
      </mx:FormItem>
      <mx:FormItem label="Country">
      <mx:TextInput id="tempCountry"/>
      </mx:FormItem>
      </mx:Form>
      </mx:Accordion>
        • 1. Re:  Muiltiple forms + addEventListener not working
          Bayani Portier Level 1
          Maybe I'm just missing something.

          permCountry.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, tabAccordian);
          <mx:TextInput id="tempCountry"/>

          where is permCountry defined?
          • 2. Re:  Muiltiple forms + addEventListener not working
            SujitG Level 2
            Hi,

            I modified your code to the following. Both the event listeners are getting registered.

            Hope this helps.

            private function init():void{
            //This first event listener gets set but the second one does not...
            Email.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, tabAccordian);
            }

            private function init2():void{
            //This first event listener gets set but the second one does not...
            permCountry.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, tabAccordian);

            }

            private function tabAccordian(fEvent:FocusEvent):void{
            //Alert.show(fEvent.currentTarget.toString());
            formAccordion.selectedIndex += 1;
            }

            ]]>
            </mx:Script>

            <mx:Accordion id="formAccordion" width="100%" height="510">
            <mx:Form id="applicantData" label="Personal Information (1-6)" creationComplete="init()" >
            <mx:FormItem label="Last Name">
            <mx:TextInput id="lastName" tabIndex="1"/>
            </mx:FormItem>
            <mx:FormItem label="First Name">
            <mx:TextInput id="firstName" tabIndex="1"/>
            </mx:FormItem>
            <mx:FormItem label="Email">
            <mx:TextInput id="Email" tabIndex="2"/>
            </mx:FormItem>
            </mx:Form>

            <mx:Form id="permAddress" label="Permanent Address (7)" creationComplete="init2()">
            <mx:FormItem label="House or Building #">
            <mx:TextInput id="permHouseNum" width="60" tabIndex="10"/>
            </mx:FormItem>
            <mx:FormItem label="Country">
            <mx:TextInput id="permCountry"/>
            </mx:FormItem>
            </mx:Form>
            </mx:Accordion>
            • 3. Re:  Muiltiple forms + addEventListener not working
              khitlin Level 1
              Hey guys,
              Thanks for the replies, I did try having multiple inits, and that did work. But the bigger issue is why can't I assign an eventHandler for fields within multiple forms in one main init? This seems like a bug to me. Anyone from Adobe want to pipe in on this?
              • 4. Re:  Muiltiple forms + addEventListener not working
                SujitG Level 2
                Hi,

                You can do this in one init() function also. You will get RTE because the Accordion control will not create all the children by default, it will only create the children which are visible. If you set the creatioPolicy of your Accordion control to "all" then you can do all in one init() function. Please check the URL below for more details on creationPolicy.
                http://livedocs.adobe.com/flex/3/html/layoutperformance_05.html#131483

                Hope this helps.