Skip navigation
Currently Being Moderated

Issue with Combo box AS2

Jul 10, 2012 3:03 AM

Tags: #help #flash #as2 #actionscript #comboboxes

Hi.

 

Please can someone advise me. I have two combo boxes on the timeline which on select go to a particular frame. One has an instance name of 'dropdownIN' the other 'dropdownIN2'. I am using the code below for event listner, but only the first combo box works. Both combo boxes have a change handler called 'onSelect'. How can I modify the code below so that I can have multiple combo boxes on my page.

 

initData();

function onSelect() {

gotoAndStop(dropdownIN.getSelectedItem().data);

} listenerObject = new Object();

listenerObject.change = function(eventObject) {

getURL(eventObject.target.value);

}

dropdownIN.addEventListener("change" , listenerObject)

;

initData1();

function onSelect() {

gotoAndStop(dropdownIN2.getSelectedItem().data);

} listenerObject = new Object();

listenerObject.change = function(eventObject){

getURL(eventObject.target.value);

}

dropdownIN2.addEventListener("change2" , listenerObject) ;

 
Replies
  • Currently Being Moderated
    Jul 10, 2012 5:27 AM   in reply to BinaryBloke

    Write distinct code for each combobox.  You cannot have two functions named the same, only one can work (if either will... AS3 would not permit it at all) You cannot have two "listenerObject"s defined, again, only one will survive.  You can however have code shared.  See if the following works (I am not sure about the details, but I removed the onSelect function)...

     

    var listenerObject = new Object();


    listenerObject.change = function(eventObject){
        getURL(eventObject.target.value);
        gotoAndStop(eventObject.getSelectedItem().data);
    }

     

    dropdownIN.addEventListener("change", listenerObject) ;
    dropdownIN2.addEventListener("change" , listenerObject) ;

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 10, 2012 6:35 AM   in reply to BinaryBloke

    I added some information to my original response if you want to check back there.

     

    Layers will not help.  I am saying you cannot define two "onSelect" functions in the same file... which one will the program choose?  Similarly, you cannot redefine the listenerObject as you do... the last definition is all that will survive... there will not /cannot be two different ones with the same name.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 10, 2012 10:05 AM   in reply to BinaryBloke

    What you should do now is place some traces in the change function to see if it is being executed.  You can trace the values that you are using within it to see what they are....

     

    listenerObject.change = function(eventObject){

       trace(eventObject.target.value);

       trace(eventObject.getSelectedItem().data);

       getURL(eventObject.target.value);

       gotoAndStop(eventObject.getSelectedItem().data);

    }

     

    if the traces appear you know the function is executing, which means you know the listeners are working, you just need to see what the values you are trying to process are.  I cannot answer for them since I cannot see the data you are loading.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 11, 2012 4:39 AM   in reply to BinaryBloke

    As per my previous reply, you now know the listeners are working.  You need to figure out what data it is that you are trying to get since that would appear to be the source of the problem. 

     

    I cannot tell what it should be, but if you take those trace outputs and try to run them in those getURL and gotoAndStop commands you aren't likely to get anywhere with them.  A getURL requires a URL to get, and a gotoAndStop requires a frame number or frame label.  None of what you show as the trace outputs qualifies.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 11, 2012 5:52 AM   in reply to BinaryBloke

    Same here

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 11, 2012 6:40 AM   in reply to BinaryBloke

    Going back to basics, you need to determine what data you are after.  I do not know what is represented by the data you are trying to use, which are...

     

    eventObject.target.value

    eventObject.getSelectedItem().data

     

    You need to resolve the data to be what it is supposed to be.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points