4 Replies Latest reply on May 22, 2006 3:40 AM by MysteriousBob

    comboxBox - events

    dirkness
      Hi

      I've built a simple comboBox using the Flash 8 help - I'm looking for some help on setting-up the actionscript (event listener) to send the timeline to a different frame when the user clicks 1 of the combo list items.

      So the comboBox was set-up in the usual way - I input 3 labels (bristol, birmingham and manchester) in the parameters label section - and added the script below on frame 1 of the movie:

      [code]function change(evt){
      trace(evt.target.selectedItem.label);
      }
      comboBox.addEventListener("change", this); [/code]

      So far so good - the comboBox functions as it should.


      Now I'd like to send the main timeline to a different frame everytime the user clicks on the comboBox labels (so for bristol - gotoFrame 10; manchester - gotoFrame 20; birmingham - gotoFrame 30 etc).


      Flash help gives the following actionscript to implement comboBox commands:

      [code]// Add Item to List.
      my_cb.addItem({data:1, label:"First Item"});
      my_cb.addItem({data:2, label:"Second Item"});

      // Create Listener Object.
      var cbListener bject = new Object();

      // Assign function to Listener Object.
      cbListener.change = function(event_obj bject) {
      trace("Value changed to: "+event_obj.target.selectedItem.label);
      };

      // Add Listener.
      my_cb.addEventListener("change", cbListener);[/code]


      This seems to repopulate the labels - and doesn't explain how I apply a gotoFrame function for different lable items in the comboBox drop-down menu.


      Grateful for any help on getting this set-up.

      Thanks

      Dirk
        • 1. Re: comboxBox - events
          Peter Lorent Level 2
          >>This seems to repopulate the labels
          Yes, the following lines overrule your settings in the component inspector:
          my_cb.addItem({data:1, label:"First Item"});
          my_cb.addItem({data:2, label:"Second Item"});

          As you can see, an item has a data property and a label property. Using the data property you could use the following code:
          // Add Item to List.
          my_cb.addItem({data:10, label:"Bristol"});
          my_cb.addItem({data:20, label:"Birmingham"});
          my_cb.addItem({data:30, label:"Manchester"});

          // Create Listener Object.
          var cbListener:Object = new Object();

          // Assign function to Listener Object.
          cbListener.change = function(event_obj:Object) {
          switch (event_obj.target.selectedItem.data){
          case 10:
          _level0.gotoAndPlay(10);
          break;
          case 20:
          _level0.gotoAndPlay(20);
          break;
          case 30:
          _level0.gotoAndPlay(30);
          break;
          }
          trace("Value changed to: "+event_obj.target.selectedItem.label);
          };

          // Add Listener.
          my_cb.addEventListener("change", cbListener);

          This line adds an item to the combobox and we use the data property to hold the desired frame to go to:
          my_cb.addItem({data:10, label:"Bristol"});

          The switch statement uses the data property of the selected item to evaluate which frame to go to:
          switch (event_obj.target.selectedItem.data){
          • 2. Re: comboxBox - events
            Level 7
            >>This seems to repopulate the labels
            Yes, the following lines overrule your settings in the component inspector:
            my_cb.addItem({data:1, label:"First Item"});
            my_cb.addItem({data:2, label:"Second Item"});

            As you can see, an item has a data property and a label property. Using the
            data property you could use the following code:
            // Add Item to List.
            my_cb.addItem({data:10, label:"Bristol"});
            my_cb.addItem({data:20, label:"Birmingham"});
            my_cb.addItem({data:30, label:"Manchester"});

            // Create Listener Object.
            var cbListener bject = new Object();

            // Assign function to Listener Object.
            cbListener.change = function(event_obj bject) {
            switch (event_obj.target.selectedItem.data){
            case 10:
            _level0.gotoAndPlay(10);
            break;
            case 20:
            _level0.gotoAndPlay(20);
            break;
            case 30:
            _level0.gotoAndPlay(30);
            break;
            }
            trace("Value changed to: "+event_obj.target.selectedItem.label);
            };

            // Add Listener.
            my_cb.addEventListener("change", cbListener);

            This line adds an item to the combobox and we use the data property to hold
            the desired frame to go to:
            my_cb.addItem({data:10, label:"Bristol"});

            The switch statement uses the data property of the selected item to evaluate
            which frame to go to:
            switch (event_obj.target.selectedItem.data){

            • 3. Re: comboxBox - events
              dirkness Level 1
              Thanks for that -- got it working
              • 4. Re: comboxBox - events
                MysteriousBob
                I have found an alternative to the additem method.
                try Combo_Box_Name.dataProvider

                I have a Media Type combo and a Description combo.

                The decscription combo changes depending on the Media Type selected.