Welcome, Guest
  • Author Topic: binding buttons to combobox  (Read 1392 times)

    pheck

    • Server what's that
    • *
    • Posts: 30
      • View Profile
      • Doctored Media
      • Email
    binding buttons to combobox
    « on: 12/11/04, 02:45 »
    I followed this tutorial at MM and found it to be helpful.

    http://www.macromedia.com/devnet/mx/flash/articles/xmlconnector.html

    I have a similar setup as this example.  Basically, I have a combobox that gets populated by an xml file.  Through data binding, when I change my selection in the combobox, new text is displayed in a textArea component and a new step is played in a movie loaded in by a loader component.  This all works great.  But what I am trying to do is add another navigation scheme.  I want next and previous buttons to change the step played in the loaded in movie, the text displayed in the textArea component, and the combobox selection.  The current code (below) does everything right except change the textArea to the right text.  I would have thought changing the selectedIndex of the combobox would have done this automatically since it is bound to the textArea?  How can I modify my code to get my buttons in on the binding action?  Thanks.

    Code: [Select]

    //--- Execution
    comboListener = new Object();
    myStep.addEventListener("change", comboListener);
    btnListener = new Object();
    nextBtn.addEventListener("click", btnListener);
    prevBtn.addEventListener("click", btnListener);
    //--- Functions
    btnEnabler = function(){
       if(myStep.selectedIndex == 0){
          prevBtn.enabled = false;
       } else {
          prevBtn.enabled = true;
       } if(myStep.selectedIndex+1 == myStep.length){
          nextBtn.enabled = false;
       } else {
          nextBtn.enabled = true;
       }
    }
    btnListener.click = function(evt){
       if(evt.target == prevBtn) myStep.selectedIndex--;
       if(evt.target == nextBtn) myStep.selectedIndex++;
       myLoader.content.gotoAndPlay("step"+(myStep.selectedIndex+1));
       btnEnabler();
    }
    comboListener.change = function(){
       myLoader.content.gotoAndPlay("step"+(myStep.selectedIndex+1));
       btnEnabler();
    }

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re:binding buttons to combobox
    « Reply #1 on: 12/11/04, 05:10 »
    The comboListener.change doesn't firewhen manually changing selectedIndex. Add this line to the btnListener.click function:

    comboListener.change()

    Jorge

    pheck

    • Server what's that
    • *
    • Posts: 30
      • View Profile
      • Doctored Media
      • Email
    Re:binding buttons to combobox
    « Reply #2 on: 12/11/04, 09:33 »
    Thanks for the help Jorge, but that doesn't work.

    comboListener.change()

    is a function that I defined, and does a couple things the btnListener already does.  So when I put that line in btnListener, it is doing some things twice.  Did you mean to say "add this line to btnListener:  myStep.change()" where myStep is the instance name of my combobox component?  That didn't work either.

    Again, I appreciate the help.  If you can think of another way to get my combobox basically to refresh itself so that other bound entities refresh as well, I think that would be the solution.  Any ideas?

    pheck

    • Server what's that
    • *
    • Posts: 30
      • View Profile
      • Doctored Media
      • Email
    solution
    « Reply #3 on: 12/13/04, 00:11 »
    For those of you interested, I figured out the solution.  The trick is to use the dispatchEvent().  Calling the change() function won't do it by itself as this function is fired as a result of an event; it isn't an event in itself, so you have to manually dispatch an event.

    Code: [Select]
    //--- Execution
    comboListener = new Object();
    myStep.addEventListener("change", comboListener);
    btnListener = new Object();
    nextBtn.addEventListener("click", btnListener);
    prevBtn.addEventListener("click", btnListener);
    //--- Functions
    btnEnabler = function(){
       if(myStep.selectedIndex == 0){
          prevBtn.enabled = false;
       } else {
          prevBtn.enabled = true;
       } if(myStep.selectedIndex+1 == myStep.length){
          nextBtn.enabled = false;
       } else {
          nextBtn.enabled = true;
       }
    }
    btnListener.click = function(evt){
       if(evt.target == prevBtn) myStep.selectedIndex--;
       if(evt.target == nextBtn) myStep.selectedIndex++;
       myStep.dispatchEvent({type:"change"});
    }
    comboListener.change = function(){
       myLoader.content.gotoAndPlay("step"+(myStep.selectedIndex+1));
       btnEnabler();
    }
    « Last Edit: 12/13/04, 00:12 by pheck »