A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: setValue() Not Working with a Combo Box

  1. #1
    Junior Member
    Join Date
    Jan 2002
    Posts
    24

    setValue() Not Working with a Combo Box

    I am having trobule with the setValue() not working for a combo box.

    Here is the code that I'm using to test it..

    function getValueOfItem() {
    valueOfItem = listINVENTORY.getValue();
    statusMessage = 'getValue..';
    }

    function setValueOfItem() {
    listINVENTORY.setValue(valueOfItem);
    statusMessage = 'setValue..';
    }


    The two functions above are attached to buttons. I select a value
    from my drop down, click the button attached to the "get value" function above, change the value of the drop down and then click the button attached to the "set value" function above. I know that both functions are being called because the status message updates, yet the combo box does not..

    What's the deal?

    Rich

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    is your combo set to editable = true ??
    myComboBox.setEditable(true);

    setValue can be used only with editable combo boxes.

    hth

  3. #3
    Junior Member
    Join Date
    Jan 2002
    Posts
    24
    Hi..

    Thanks for the info.. I'll give that a try.

    Whats wierd is that I got "setIndex()" to work..

    Rich

  4. #4
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    do you mean setSelectedIndex();

    myComboBox.setSelectedIndex(3);
    //selects the fourth item in the list

    if you want to add content to a combo,
    check the reference for -
    FComboBox.addItem and FComboBox.addItemAt

  5. #5
    Junior Member
    Join Date
    Jan 2002
    Posts
    24
    Hi..

    Yes, I did mean setSelectedIndex()


    Okay.. here's a problem now..

    I tried to set to change the "editable" programaticlly

    listINVENTORY.setEditable(true);
    listINVENTORY.setValue(valueOfItem);
    listINVENTORY.setEditable(false);

    because I don't want users to be able to edit the text in the list, but this didn't work.

    So I changed the setting at design time and it worked.. however, the problem with the way it "worked" is that when I read the value from my combo box, the value has changed.. what I mean by this is that I have setup my combo box so that the "VALUE" is 1,2,3,4, etc.. and the displayed text is "one","two","three","four"

    When I have editable set to false and I read the value, I get "1" or "2", etc..

    When I have editable set to true and I read the value, I get "one", "two", etc..

    This is bad.. I need to always be able to read "1", "2", etc..

    ?!?!?! Any ideas?

    Thanks,

    Rich

  6. #6
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    getValue is working as designed -

    Method; returns the text in the field at the top of the combo box, if the combo box is editable. If the combo box is static (not editable), this method returns the data associated with the selected item, or the label of the item if no data is associated.

    what is it that you are trying to do with the use of -

    setValue -
    Method; specifies the text displayed in the input field at the top of an editable combo box.

  7. #7
    Junior Member
    Join Date
    Jan 2002
    Posts
    24
    This is the code that I've created to do what I want to do. I have the values in the combo box "listINVENTORY" stored in an array called "varItemsIdArray" and so I've created a function to figure out the index of a particular value in the array.

    Array.prototype.fIndexOf = function(findValue)
    {
    i = this.length;
    for (x=0; x<i; x++) {
    if (this[x] == findValue) { vIndexOf = x }
    }
    return vIndexOf;
    }

    inputITEMID.onKillFocus = function(field) {
    listINVENTORY.setSelectedIndex(varItemsIdArray.fIn dexOf(varInputItemId));
    }


    Are the "values" of the listbox (as access from getValue() when editable is set to false) available in an array built in to the component?


    Thanks,
    Rich

  8. #8
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    can you post a fla,
    strip it out to the combos, functions and arrays if possible,
    i'll take a look

  9. #9
    Junior Member
    Join Date
    Jan 2002
    Posts
    24
    Hi..

    I've figured out that the variables are accessible..

    But the array is an array of an object, so it won't work straight away with the function I've written. I'll have to modify it for use with the combo box. I'll post that code when I've done it.

    Rich

  10. #10
    Junior Member
    Join Date
    Jan 2002
    Posts
    24
    So here is the code..


    Array.prototype.fIndexOfData = function(findValue)
    {
    i = this.length;
    for (x=0; x<i; x++) {
    if (this[x].data == findValue) { vIndexOf = x }
    }
    return vIndexOf;
    }


    You can call it like this:

    listINVENTORY.setSelectedIndex(listINVENTORY.dataP rovider.items.fIndexOfData(DATATOFIND));

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