A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: combo box button actions

  1. #1
    Member
    Join Date
    Oct 2001
    Posts
    77

    combo box button actions

    Hi Everyone,

    I have looked around, and found a lot of stuff, but nothing I need. All I am trying to do is have a combo box pull down label add score to a dynamic text field. I have labeled the pull downs and added data labels as well. this is what I have used to see the trace action.

    function change(evt){
    trace(evt.target.selectedItem.label);
    }
    mycomboBox.addEventListener("change", this);

    This shows the label in output, but I need to add the scoring to the click action, different amounts for different labels.

    I would appreciate any help at all.

    Thanks

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Ummm, have you tried this?

    Actionscript Code:
    function change(evt){
        someTextField.text = evt.target.selectedItem.data;
    }
    mycomboBox.addEventListener("change", this);
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Member
    Join Date
    Oct 2001
    Posts
    77

    Thanks Nig 17

    I wish I would have started when you did.

    That code puts the data name in the score box, but I need it to add score to the scoreBox Different labels will have different scores that add up. Do I put the score adding into the data area of the component? Right now I just have for example label - housing photos data - housing


    Thanks for your help

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Really confused, could you possibly post the FLA File >.<?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  5. #5
    Member
    Join Date
    Oct 2001
    Posts
    77

    I am asking the question poorly

    What I am really trying to do is make the combo box pull down labels, useable as buttons, adding to score, disabling, making movie clips do things, I like the look but I am used to using buttons and button actions, new to the combo box deal.

    Thank You

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    But you have to tell what are you trying to achive so we know where to start helping you. What things have you tried already?

  7. #7
    Member
    Join Date
    Oct 2001
    Posts
    77

    Thanks Angelhdz

    If I understand one I will understand the rest of it. One thing I want to do is the person pulls down the menu of the combo box, makes a selection, and that trigger creates a score value of lets say 5 into the dynamic text score box. The user selects a different label on the menu and it adds another 5 to the score, making it 10, and so on. If I can figure out how to do that, I will be able to do the rest of the things I want to do, like disable the label once the person has used it once.


    Thanks for any help you can send my way.

  8. #8
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Ok. It is easy. The combo box has methods events and properties.

  9. #9
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Actionscript Code:
    import mx.controls.ComboBox;

    var score:Number = 0;
    var cb:ComboBox = this.createClassObject(ComboBox, "cb", 0);
    cb.dataProvider = [{label:"Select Item from list", data:0}, {label:"Housing 1", data:1}, {label:"Housing 2", data:2}, {label:"Housing 3", data:3}];

    cb._x = 20;
    cb._y = 20;

    cb.setSize(cb.textField.focusTextField.textWidth+30);

    var cbListener:Object = new Object();

    cbListener.change = function(obj:Object) {
        if (obj.target.selectedItem.data != 0) {
            score += obj.target.selectedItem.data;
            txt.text=(score);
            trace("Selected Item: "+obj.target.selectedItem.label);
        }
    };
    cb.addEventListener("change",cbListener);



    poltuda

  10. #10
    Member
    Join Date
    Oct 2001
    Posts
    77

    Thanks Poltuda

    I will try this as soon as I get to work in the morning, appreciate the help!

  11. #11
    Member
    Join Date
    Oct 2001
    Posts
    77

    works great

    Thanks, that works great, I have multiple combo boxes however, when I tried to add this code to other boxes I got the message "already using the mx.control" something like that. How do I have mulitple combo boxes on the page? One more thing, is there a way to "disable" the label and data point after the user selects it so they cannot select it again?


    Thanks for your assistance!

  12. #12
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Actionscript Code:
    import mx.controls.ComboBox;

    var score:Number = 0;
    var cb:ComboBox = this.createClassObject(ComboBox, "cb0", this.getNextHighestDepth());
    cb.dataProvider = [{label:"Select Item from list", data:0}, {label:"Housing 1", data:1,enabled:true}, {label:"Housing 2", data:2,enabled:true}, {label:"Housing 3", data:3,enabled:true}];
    cb._x = 20;
    cb._y = 20;
    cb.setSize(cb.textField.focusTextField.textWidth+30);
    cb.addEventListener("change",cbListener);
    cb = this.createClassObject(ComboBox, "cb1", this.getNextHighestDepth());
    cb.dataProvider = [{label:"Select Item from list", data:0}, {label:"Housing 1", data:1,enabled:true}, {label:"Housing 2", data:2,enabled:true}, {label:"Housing 3", data:3,enabled:true}];
    cb._x = 200;
    cb._y = 20;
    cb.setSize(cb.textField.focusTextField.textWidth+30);
    cb.addEventListener("change",cbListener);

    function cbListener(obj:Object) {
        if (obj.target.selectedItem.data != 0) {
            if (obj.target.selectedItem.enabled) {
                obj.target.selectedItem.enabled = false;
                score += obj.target.selectedItem.data;
                txt.text = (score);
                trace("Selected Item: "+obj.target.selectedItem.label);
            }
        }
    }


    Basic example.



    poltuda
    Last edited by poltuda; 07-31-2012 at 11:01 AM.

  13. #13
    Member
    Join Date
    Oct 2001
    Posts
    77
    Thanks I will try that right now. Good to see that you can have more than one in the same frame!

  14. #14
    Member
    Join Date
    Oct 2001
    Posts
    77

    You're the man.

    That works great, I designed a nice looking digital display for the score, and it is awesome that the label points are disabled after use, perfect. One thing I wanted to add was a display of the selected value, so they could see what was being added or subtracted as they went along. I created a "previewScore" dynamic text box, but it does not seem to want to show more than the selected values from one of the combo boxes, I would like to get it working so that when their score drops 20 points, they will have some warning on the other digital read out

    Thanks, Great Help.

  15. #15
    Member
    Join Date
    Oct 2001
    Posts
    77
    Adding to what you provided earlier, I tried some things and stumbled accross a solution.

    _root.scorepreview.text = obj.target.seclectedItem.data

    It now shows selected value on all combo boxes, thanks for all help on this (RESOLVED!)

  16. #16
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Actionscript Code:
    _root.scorepreview.text = obj.target.seclectedItem.data
    Change to this:
    Actionscript Code:
    _root.scorepreview.text = obj.target.selectedItem.data

    I didn't understood what you are saying. Please explain



    poltuda

  17. #17
    Member
    Join Date
    Oct 2001
    Posts
    77
    I just wanted the value of the combo box selection to show up in a dynamic text window so the person could see why the total score went up or down. I was not able to get it to work from all combo boxes, just one. I added the line of text on previous post below the "if statements" on what you showed me previously, works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center