9 Replies Latest reply on Jul 15, 2011 10:01 PM by kglad

    ComboBox and dynamic data ??

    Tony Heagren Level 1

      Hi all,

       

      I'm using php to pass FlashVars to my movie for a list of courses and dates - this works fine.

      The data from FlashVars comes in as simple strings.

       

      I then want to use two comboboxes to list the courses and the dates those courses are available.

       

      I tried this and MANY other versions but to no avail. (See code attached).

      I've also been playing withComboBox.removeItemAt() and ComboBoxReplaceItemAT() but again to no avail.

      Any ideas most welcome...

       

      Best wishes

      Tony

       

      - - - - - - - - - - -

       

      CODE:

       

      //  GET COURSE NAMES DATA
      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() {
          post = (course_cb.value);
          date_cb.enabled = 1;
          date_cb._alpha = 100;
          if (course_cb.label = _root.course_name1) {
              date_cb.addItem({data:_root.course_date1, label:course_date2});
          } else if (course_cb.label = _root.course_name2) {
              date_cb.addItem({data:_root.course_date2, label:_root.course_date3});
          } else if (course_cb.label = _root.course_name3) {
              date_cb.addItem({data:_root.course_date3, label:_root.course_date3});
          } else if (course_cb.label = _root.course_name4) {
              date_cb.addItem({data:_root.course_date4, label:_root.course_date4});
          }   
      };

        • 1. Re: ComboBox and dynamic data ??
          kglad Adobe Community Professional & MVP

          is that code executed after those variables are defined???  use the trace() function to confirm they are not defined at that time.

          • 2. Re: ComboBox and dynamic data ??
            Tony Heagren Level 1

            Hi kglad,

             

            Hmmm - not quite sure I follow you. Wasn't aware I declared any variables. I thought I'd just pulled the variables from

            flashVars and run them into the data and label sections of the cmobo (!).   What trace shoudl I run ?  (and why) ?

            I know Flash is getting all the flashVars - do I have the code in the wrong order ?

             

             

             

            For clarity, the "original" data is on an sql DB. This is pulled out by this php query:

             

            $sql = mysql_query("SELECT * FROM live_1");
            while($row = mysql_fetch_array($sql)){
            $course_name1 = $row["course_name"];
            $location1 = $row["location"];
            $course_date1 = $row["date"];
            $time1 = $row["time"];
            $places1 = $row["places"];
            $tutor1 = $row["tutor"];
            $course_num1 = $row["course_num"];
            }

             

            With the same statement repeated for ("SELECT * FROM live_2"),   $course_name2, $location2  - then 3 then 4.

            (yes I know I need to go back and tidy it into a loop but that's for another day).

             

            It's then given to flash via FlashVars in the html of the blahblah.php like this:  (embed line shown here but also has the param version)

             

                flashVars = "course_name1=<? echo"$course_name1";?> &course_date1=<? echo"$course_date1";?>&time1= <? echo"$time1";?> &places1= <? echo"$places1";?>
                            &course_name2=<? echo"$course_name2";?> &course_date2=<? echo"$course_date2";?>&time2= <? echo"$time2";?> &places3= <? echo"$places2";?>
                            &course_name3=<? echo"$course_name3";?> &course_date3=<? echo"$course_date3";?>&time3= <? echo"$time3";?> &places4= <? echo"$places3";?>
                            &course_name4=<? echo"$course_name4";?> &course_date4=<? echo"$course_date4";?>&time4= <? echo"$time4";?> &places4= <? echo"$places4";?>"

             

            The I bring it into Flash on frame 1 of the movie with the code in the first post (exactly as I posted it).

             

            My final (hopefully working) version of the movie will include two comboBoxes. With the first (course_cb) you will choose a course (while the date combo is at alpha 50 and disabled) then as you choose a course the date combo will be enabled and will display the relevant date on which that course

            is available to book yourself onto.

             

            You can see it (not working well) here:

            http://www.shutterbugclub.com/buy_order.php

             

            At present, although I have tested to prove that Flash is getting all four dates from the flashVars, only date1 is ever displayed.

             

            Again, all and any help much appreciated.

             

            Best wishes

            Monty

            • 3. Re: ComboBox and dynamic data ??
              kglad Adobe Community Professional & MVP

              copy and paste the output panel from using the trace() function:

               


               

              CODE:

               

               

              trace(course_cb+" "+_root.course_name1);

              //  GET COURSE NAMES DATA
              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() {
                  post = (course_cb.value);
                  date_cb.enabled = 1;
                  date_cb._alpha = 100;
                  if (course_cb.label = _root.course_name1) {
                      date_cb.addItem({data:_root.course_date1, label:course_date2});
                  } else if (course_cb.label = _root.course_name2) {
                      date_cb.addItem({data:_root.course_date2, label:_root.course_date3});
                  } else if (course_cb.label = _root.course_name3) {
                      date_cb.addItem({data:_root.course_date3, label:_root.course_date3});
                  } else if (course_cb.label = _root.course_name4) {
                      date_cb.addItem({data:_root.course_date4, label:_root.course_date4});
                  }   
              };

              • 4. Re: ComboBox and dynamic data ??
                Tony Heagren Level 1

                Aha.....

                 

                couldn't do a trace (developing live online - using a Mac with no local server set up as 90% of the site is php).

                But set up a dynamic text box called kglad_box (in your honour) and told flash "kglad_box = course_cb+" "+_root.course_name1;" which

                I guess gives more or less the same end result.

                 

                Output was:  _level0.course_cb Day One Digital

                 

                Day One Digital is the name of course1.

                 

                What exactly does this mean ?

                 

                The course_cb happily displays the names of all the courses (1,2,3 and 4) so what do we learn from the trace ???

                If I change the instruction to "kglad_box = course_cb+" "+_root.course_name2;"  the output is "_level0.course_cb Tune In To Programs"

                and "Tune In To Programs" is the name of course2.

                 

                Still not following you (although very grateful for your interest and help)  : )

                 

                Best wishes

                Monty

                • 5. Re: ComboBox and dynamic data ??
                  kglad Adobe Community Professional & MVP

                  i thought your combobox was not displaying the data your thought it should display.  what's the problem?

                  • 6. Re: ComboBox and dynamic data ??
                    Tony Heagren Level 1

                    Hi kglad,

                     

                    the problem is pretty simple.

                     

                    the FlashVars brings in four course names and four dates. Each date 

                    is specific to a course name.

                    i.e course_name1 relates to course_date1, course_date2 relates to 

                    course_date2   etc., etc.,

                     

                     

                    While the first combobox (course_cb) works fine in that it displays 

                    the course names. the second (date_cb)

                    does not - it only ever displays the first date (course_date1) no 

                    matter which course you choose from course_cb.

                     

                    For clarity - each course runs on a different date. The dates are in 

                    the SQL, php brings them in, converts them to flashvars and gives 

                    them to flash.

                     

                    I need the correct code for the "if" and "if / else" statements to 

                    populate the second combobox (date_cb) with the correct date 

                    dependant on

                    the users choice in the first combobox (course_cb).

                     

                    having searched EVERYWHERE and for a few days now I'm wondering if 

                    Flash is even up to this task...

                     

                    Can the list (and data) values of one comboBox be dependent (and 

                    populated dynamically) on the value chosen in another ?

                     

                    Best wishes

                    Tony

                    • 7. Re: ComboBox and dynamic data ??
                      kglad Adobe Community Professional & MVP

                      oh.


                      when testing for equality, you should use the double equal (==).  otherwise, you're assiging the left side of the = operator to have the value of the right side:

                       

                      postlisten.change = function() {
                          post = (course_cb.value);
                          date_cb.enabled = 1;
                          date_cb._alpha = 100;
                         
                          if (course_cb.selectedItem.label == _root.course_name1) {
                              date_cb.text = _root.course_date1;
                          } else if (course_cb.selectedItem.label == _root.course_name2) {
                             date_cb.text = _root.course_date2;
                          } else if (course_cb.selectedItem.label == _root.course_name3) {
                             date_cb.text = _root.course_date3;
                          } else if (course_cb.selectedItem.label == _root.course_name4) {
                              date_cb.text = _root.course_date4;
                          }
                      };

                      • 8. Re: ComboBox and dynamic data ??
                        Tony Heagren Level 1

                        Don't believe I missed such a simple syntax error....  (DOH) !

                         

                        Another issue was the use of "label" in the if statement  - when this 

                        is changed to "value" it works fine.

                         

                        SOLVED.

                         

                        Final code if anyone needs to set the contents of a second combo 

                        dependant on the user choices made in the first:

                         

                        - - - - - - - -

                         

                        // POPULATE course_cb with data from FLASH VARS in page.php

                        import mx.controls.ComboBox;

                        //  SET COURSE NAMES LABELS AND DATA

                        course_cb.addItem();

                        course_cb.addItem();

                        course_cb.addItem();

                        course_cb.addItem();

                         

                        // 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 AND REMOVE THE FIRST (ONLY) VALUE.  (JUST REMOVE 

                        MORE IF YOU HAVE MORE THEN SET

                        MORE VIA THE IF / ELSE BELOW)

                             date_cb.setSelectedIndex(0);

                             date_cb.removeItemAt(1);

                        // TEST THE VALUE OF course_cb AND POPULATE date_cb ACCORDINGLY

                             if (course_cb.value == root.coursename1) {          

                                  date_cb.addItem({data:_root.course_date1, label:_root.course_date1});

                             } else if (course_cb.value == root.coursename2) {          

                                  date_cb.addItem({data:_root.course_date2, label:_root.course_date2});

                             } else if (course_cb.value == root.coursename3) {          

                                  date_cb.addItem({data:_root.course_date3, label:_root.course_date3});

                             } else if (course_cb.value == root.coursename4) {          

                                  date_cb.addItem({data:_root.course_date4, label:_root.course_date4});

                             }     

                        };

                         

                        I'm sure the above if/else statement could be tidied into some kind 

                        of loop but while it ain't broke I ain't gonna fix it.

                         

                        Best wishes

                        Tony

                        • 9. Re: ComboBox and dynamic data ??
                          kglad Adobe Community Professional & MVP

                          you're welcome.

                           

                          p.s.  please mark helpful/correct responses, if there are any.