5 Replies Latest reply on Jul 21, 2011 5:21 PM by kglad

    Simple equality test (I thought)....

    Tony Heagren Level 1

      Hi all,

       

      Got a problem which I feel is VERY simple but no matter how I try I cannot solve it.

       

      I'm actualy using a comboBox to populate a few dynamic fields inside MCs with data from flashVars so it goes like this:

       

      // POPULATE course_cb with data from FLASH VARS in page.php
      course_cb.addItem({data:_root.course_name1, label:_root.course_name1});
      course_cb.addItem({data:_root.course_name2, label:_root.course_name2});
      course_cb.addItem({data:_root.course_name3, label:_root.course_name3});
      course_cb.addItem({data:_root.course_name4, label:_root.course_name4});

       

      and then based on the user choice of course_cb we will populate another comboBox (date_cb) like this:

       

       

       

      var postlisten:Object = new Object();
      date_cb.addEventListener("change",postlisten);
      postlisten.change = function() {

       

          if (course_cb.value == _root.course_name1) {       
              date_cb.addItem({data:_root.course_date1, label:_root.course_date1 + " @ " + time1});
          } else if (course_cb.value == _root.course_name2) {       
              date_cb.addItem({data:_root.course_date2, label:_root.course_date2 + " @ " + time2});
          } else if (course_cb.value == _root.course_name3) {       
              date_cb.addItem({data:_root.course_date3, label:_root.course_date3 + " @ " + time3});
          } else if (course_cb.value == _root.course_name4) {       
              date_cb.addItem({data:_root.course_date4, label:_root.course_date4 + " @ " + time4});
          }   
      };

       

      Now we fill in the "extra" data into three "fake" comboBoxes (MCs that just look like combos but with only a dynamic text field inside).

       

         
      // ASSIGN A VARIABLE TO IDENTIFY THE CHOICE MADE IN course_cb   
      spotsNum = course_cb.selectedIndex;
      var where:String = _root["location" + spotsNum];
      var spots:String = _root["places" + spotsNum];
      var prof:String = _root["tutor" + spotsNum];

       

      // POPULATE DYNAMIC TEXT INSIDE FAKE COMBOBOXES
      fake1.choice_dyna = where;
      fake2.choice_dyna = spots;
      fake3.choice_dyna = prof;
          fake1.gotoAndStop(2);
          fake2.gotoAndStop(2);
          fake3.gotoAndStop(2);

       

      }

       

      OK - goddit ?

      Flash Vars in and they populate course_cb.

      Choice of course_cb populates date_cb.

      Choice of date_cb populates dynamic text field in three MCs which just have graphics to look like a combo but are not combos.

       

      PROBLEM:

       

      No matter how I try, no matter what method I use, no matter how many functions I write or loops I create, I CANNOT test equality (i.e. "==" )

      on the contents of those dynamic fields inside the "fake" comboBoxes.   I'm tearing out my hair here so all and any help much appreciated.

       

      I'm starting to wonder whether FlashVars arrive as strings (I thought they did), I'm starting to wonder if I've set this up badly (althoug it seems

      very simple to me) and I'm starting to wonder about my own sanity because I've been trying to find a sloution to this for TWO DAYS    :  (

       

      Love and late nights at the keyboard

      Monty

        • 1. Re: Simple equality test (I thought)....
          kglad Adobe Community Professional & MVP

          trace your strings AND trace their length to see if they're equal.  it's common to have white space (especially with loaded variables like xml and flashvars) that look like you expect but have trailing carriage returns and spaces.

           

          if that's your problem you can use a trim function to remove trailing white space:

           

          function trimF(s:String):String{

          while(s.substr(-1,1)==" " || s.substr(-1,1)=="\r" || s.substr(-1,1)=="\n"){

          s = s.substr(0,-1)

          }

          return s;

          }

          1 person found this helpful
          • 3. Re: Simple equality test (I thought)....
            Tony Heagren Level 1

            White space - nice idea. I'll check it.

             

            PS - why does this forum keep kicking me out ?

            Every time I ome back I have to sign in, change my country, try about five times

            to reply or flag a message as "helpful" and it only woprks 50/50.

             

            A bit disapointing from Adobe...

             

            Anyway, I'm off to check for carriage returns and whicte space.

            Ca't trace it as I'm developing online (never learned how to set the Mac up as a local server).

             

            best wishes

            Tony

            • 4. Re: Simple equality test (I thought)....
              Tony Heagren Level 1

              Haha !

               

              Turns out not to be white spae but a carriage return.

              WHAT (!?!?)  where did that come from  ??????

               

              I can't trace as previously explained so I wrote this quick and dirty test to run online:

               

              if (fake2.pos_zero == "FULLY BOOKED") {
                  glory = "no white space";
                  } else if (fake2.pos_zero == "FULLY BOOKED ") {
                      glory = "white space AFTER";
                  } else if (fake2.pos_zero == "FULLY BOOKED" + "/r") {
                      glory = "carriage return";
                  } else if (fake2.pos_zero == " FULLY BOOKED") {
                      glory = "white space BEFORE";
                      } else {
                      glory = fake2.pos_zero;
              }

               

              Immmediately got the result "carriage return" and since then all is sweetness and light.

              So...

               

              New question if I may:

               

              Below is ALL of the code I'm using to populate comboBoxes (and "fake" comboBoxes) including my down and dirty test.

              Where would I best place a few lines to strip out the carriage return (and maybe white space too) and how

              exactly would I write it to target the all variables being brought in from php ?

               

              VERY grateful for your help on this and if you're ever in London let me know because you're up for a champagne dinner.

               

              Best wishes

              Tony

              _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

               

              import mx.controls.ComboBox;

               

              // POPULATE loaction_cb with data from FLASH VARS in page.php
              location_cb.addItem({data:_root.location1, label:_root.location1});

               

              // POPULATE course_cb with data from FLASH VARS in page.php
              course_cb.addItem({data:_root.course_name1, label:_root.course_name1});
              course_cb.addItem({data:_root.course_name2, label:_root.course_name2});
              course_cb.addItem({data:_root.course_name3, label:_root.course_name3});
              course_cb.addItem({data:_root.course_name4, label:_root.course_name4});

               

              // CHOOSE A COURSE and POPULATE date_cb with correct date:

               

              var postlisten:Object = new Object();
              course_cb.addEventListener("change",postlisten);
              postlisten.change = function() {
                  reset();
                  date_cb.enabled = 1;
                  date_cb._alpha = 100;
                  cancel_btn._alpha = 100;
                  cancel_btn.enabled = 1;
                  book102_mc._alpha = 100;
                  course_number = course_cb.selectedIndex;

               

                  if (course_cb.value == _root.course_name1) {       
                      date_cb.addItem({data:_root.course_date1, label:_root.course_date1 + " @ " + time1});
                  } else if (course_cb.value == _root.course_name2) {       
                      date_cb.addItem({data:_root.course_date2, label:_root.course_date2 + " @ " + time2});
                  } else if (course_cb.value == _root.course_name3) {       
                      date_cb.addItem({data:_root.course_date3, label:_root.course_date3 + " @ " + time3});
                  } else if (course_cb.value == _root.course_name4) {       
                      date_cb.addItem({data:_root.course_date4, label:_root.course_date4 + " @ " + time4});
                  }   
              };

               

              //  POPULATE AND MAKE VISIBLE ALL CHOICES BELOW date_cb

               

              var postlisten:Object = new Object();
              date_cb.addEventListener("change",postlisten);
              postlisten.change = function() {
                 
              // BASIC LOOK AND FEEL STUFF
                  fake1._alpha = 100;
                  fake2._alpha = 100;
                  fake3._alpha = 100;
              // ASSIGN A VARIABLE TO IDENTIFY THE CHOICE MADE IN course_cb   
              spotsNum = course_cb.selectedIndex;
              var where:String = _root["location" + spotsNum];
              var spots:String = _root["places" + spotsNum];
              var prof:String = _root["tutor" + spotsNum];

               

              // POPULATE FAKE COMBOBOXES AND GIVE "ACTIVE" LOOK.
              fake1.choice_dyna = where;
              fake2.pos_zero = spots;
              fake3.choice_dyna = prof;
                  fake1.gotoAndStop(2);
                  fake2.gotoAndStop(2);
                  fake3.gotoAndStop(2);
                  book_btn._alpha = 100;
                  book_btn.enabled = 1;

               

              // TEST FOR ZERO PLACES ON ANY COURSE

              // quick and dirty test for white space either end and carriage returns !!!!!


              if (fake2.pos_zero == "FULLY BOOKED") {
                  glory = "no white space";
                  } else if (fake2.pos_zero == "FULLY BOOKED ") {
                      glory = "white space AFTER";
                  } else if (fake2.pos_zero == "FULLY BOOKED" + "/r") {
                      glory = "carriage return";
                  } else if (fake2.pos_zero == " FULLY BOOKED") {
                      glory = "white space BEFORE";
                      } else {
                      glory = fake2.pos_zero;
                   }

               

              };

              • 5. Re: Simple equality test (I thought)....
                kglad Adobe Community Professional & MVP

                carriage returns count as white space and the trimF() i suggested you use will remove them.

                 

                apply it to your flashvars variables.  so if, for example, _root.location1 is a flashvars variable, use:

                 

                trimF(_root.location1)

                 

                instead of

                 

                _root.location1

                 

                or, if you're using each variable multiple times and you want to save typing, before you use your flashvars variables, use:

                 

                _root.location1 = trimF(_root.location1)

                1 person found this helpful