11 Replies Latest reply: Oct 5, 2013 12:36 PM by kglad RSS

    tabIndex

    Ron Colmen Community Member

      If I have multiple movieclips with text fields (TF instance names are different in in each mc);

      How do I set the tabIndex for each set of textfields in each movieclip to be looping correctly?

        • 1. Re: tabIndex
          kglad CommunityMVP

          use their tabIndex property:

           

          mc1.tf1.tabIndex=1;

          mc1.tf2.tabIndex=2;

          mc2.tf1.tabIndex=3;

          etc

          • 2. Re: tabIndex
            Ron Colmen Community Member

            Appologies.

            This is my code, Doesn't seem to work?

            Also How can I shorten the code? There are more than 15 movieclips with texfFields to be included here.

             

            var tf1:Array=[_root.my_mc1.tf1, _root.my_mc1.tf3, _root.my_mc1.tf2];

            var tf2:Array=[_root.new_mc2.tf2, _root.new_mc2.tf1, _root.new_mc2.tf2];

            var tf3:Array=[_root.b_mc3.tf3, _root.b_mc3.tf1, _root.b_mc3.tf2];

            var tf4:Array=[_root.fin.txf2, _root.fin.txf3, _root.fin.txf1];

             

            for (i=0; i<tf1.length; i++) {

                tf1[i].onChanged = changeF;

            }

            for (i=0; i<tf2.length; i++) {

                tf2[i].onChanged = changeF;

            }

            for (i=0; i<tf3.length; i++) {

                tf3[i].onChanged = changeF;

            }

            for (i=0; i<tf4.length; i++) {

                tf4[i].onChanged = changeF;

            }

            function changeF(tf:TextField):Void{

                if(memberOf(tf1,tf)){

                    for (i=0; i<tf1.length; i++) {

                        tf1[i].tabIndex = i;

                    }

                    for (i=0; i<tf2.length; i++) {

                        tf2[i].tabIndex = null;

                    }

                                for (i=0; i<tf3.length; i++) {

                        tf3[i].tabIndex = null;

                    }

                                for (i=0; i<tf4.length; i++) {

                        tf4[i].tabIndex = null;

                    }

                }

                      if(memberOf(tf2,tf)){

                    for (i=0; i<tf1.length; i++) {

                        tf1[i].tabIndex = null;

                    }

                    for (i=0; i<tf2.length; i++) {

                        tf2[i].tabIndex = i;

                    }

                                for (i=0; i<tf3.length; i++) {

                        tf3[i].tabIndex = null;

                    }

                                for (i=0; i<tf4.length; i++) {

                        tf4[i].tabIndex = null;

                    }

                }

                      if(memberOf(tf3,tf)){

                    for (i=0; i<tf1.length; i++) {

                        tf1[i].tabIndex = null;

                    }

                    for (i=0; i<tf2.length; i++) {

                        tf2[i].tabIndex = null;

                    }

                                for (i=0; i<tf3.length; i++) {

                        tf3[i].tabIndex = i;

                    }

                                for (i=0; i<tf4.length; i++) {

                        tf4[i].tabIndex = null;

                    }

                }

                      else {

                    for (i=0; i<tf2.length; i++) {

                        tf2[i].tabIndex = null;

                    }

                    for (i=0; i<tf1.length; i++) {

                        tf1[i].tabIndex = null;

                    }

                                for (i=0; i<tf3.length; i++) {

                        tf3[i].tabIndex = null;

                    }

                    for (i=0; i<tf4.length; i++) {

                        tf4[i].tabIndex = i;

                    }

                }

            }

             

             

            function memberOf(a,e):Boolean{

                for(var i:Number=0;i<a.length;i++){

                    if(a[i]==e){

                        return true;

                    }

                }

                return false;

            }

            • 3. Re: tabIndex
              kglad CommunityMVP

              what tab order do you want?

              • 4. Re: tabIndex
                Ron Colmen Community Member

                Thanks for the reply kglad.

                Basically in the above code, once i start typing in any of the 12 text fields, I want to be able to tab thru the text fields wihtin the relevant movieclip.

                 

                Also since there are around 17 movieclips in total with text fields, I'm not sure if the above method wouldn't be the ideal way to do this?

                • 5. Re: tabIndex
                  kglad CommunityMVP

                  :

                  var tl:MovieClip=this;

                  var tf1:Array=[_root.my_mc1.tf1, _root.my_mc1.tf3, _root.my_mc1.tf2];

                  var tf2:Array=[_root.new_mc2.tf2, _root.new_mc2.tf1, _root.new_mc2.tf2];

                  var tf3:Array=[_root.b_mc3.tf3, _root.b_mc3.tf1, _root.b_mc3.tf2];

                  var tf4:Array=[_root.fin.txf2, _root.fin.txf3, _root.fin.txf1];

                   

                  for(var i:Number=1;i<=4;i++){

                  for(var j:Number=0;j<this["tf"+i].length;j++){

                  tl["tf"+i][j].onSetFocus=focusF;

                  }

                  }

                   

                  function focusF():Void{

                  for(var i:Number=1;i<=4;i++){

                  if(memberOf(this,tl["tf"+i])){

                  for(var j:Number=0;j<tl["tf"+i].length;j++){

                  tl["tf"+i][j].tabIndex=j;

                  }

                  break;

                  }

                  }

                  }

                   

                  function memberOf(e,a):Boolean{

                      for(var i:Number=0;i<a.length;i++){

                          if(a[i]==e){

                              return true;

                          }

                      }

                      return false;

                  }

                  • 6. Re: tabIndex
                    Ron Colmen Community Member

                    Thank you and congratulations for reaching the 6 figure points!

                    • 7. Re: tabIndex
                      kglad CommunityMVP

                      you're welcome.

                       

                      (and thank you!)

                      • 8. Re: tabIndex
                        Ron Colmen Community Member

                        This works almost perfectly but it doesn't recoganize the active mc.

                         

                        e.g. If the user input data in tf3 (works perfectly) and then starts typing in tf1,  it tabs thru tf1 and tf3. can the tabIndex work only for within the active mcs textFields?

                         

                        function focusF():Void{

                        for(var i:Number=1;i<=4;i++){

                        if(memberOf(this,tl["tf"+i])){

                        for(var j:Number=0;j<tl["tf"+i].length;j++){

                        tl["tf"+i][j].tabIndex=j;

                        trace(tl["tf"+i][j]+"     "+j)

                        }

                        break;

                        }

                        }

                        }

                         

                        trace

                        _level0.b_mc3.tf3     0

                        _level0.b_mc3.tf1     1

                        _level0.b_mc3.tf2     2

                        _level0.b_mc3.tf3     0

                        _level0.b_mc3.tf1     1

                        _level0.b_mc3.tf2     2

                        _level0.b_mc3.tf3     0

                        _level0.b_mc3.tf1     1

                        _level0.b_mc3.tf2     2

                        _level0.my_mc1.tf1     0

                        _level0.my_mc1.tf3     1

                        _level0.my_mc1.tf2     2

                        _level0.b_mc3.tf3     0

                        _level0.b_mc3.tf1     1

                        _level0.b_mc3.tf2     2

                        _level0.my_mc1.tf1     0

                        _level0.my_mc1.tf3     1

                        _level0.my_mc1.tf2     2

                        _level0.b_mc3.tf3     0

                        _level0.b_mc3.tf1     1

                        _level0.b_mc3.tf2     2

                        • 9. Re: tabIndex
                          kglad CommunityMVP

                          use:

                           

                          function focusF(): Void {

                              for(var i: Number = 1; i <= 4; i++) {

                                  if(memberOf(this, tl["tf" + i])) {

                                      for(var j: Number = 0; j < tl["tf" + i].length; j++) {

                                          tl["tf" + i][j].tabIndex = j;

                                          tl["tf" + i][j].tabEnabled = true;

                                      }

                                  } else {

                                      for(var j: Number = 0; j < tl["tf" + i].length; j++) {

                                          tl["tf" + i][j].tabEnabled = false;

                                      }

                                  }

                              }

                          }

                          • 10. Re: tabIndex
                            Ron Colmen Community Member

                            brilliant!! Thanks.

                            • 11. Re: tabIndex
                              kglad CommunityMVP

                              you're welcome.