A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: comboBox on(change)?

  1. #1
    Style before Substance
    Join Date
    Mar 2003
    Location
    Geneva, Switz.
    Posts
    202

    comboBox on(change)?

    Why can't I add an on(change) handler to my comboBox!?!

    This is really driving me mad. I place a comboBox on the stage, select it, give it an instance name, then add the following actionscript:
    Code:
    on(change){
       trace("hello");
    }
    ... but when I try to run it I get the following errors:
    Scene=Scene 1, Layer=Layer 14, Frame=1: Line 14: Invalid mouse event specified.
    on(change){

    Scene=Scene 1, Layer=Layer 14, Frame=1: Line 15: Statement must appear within on/onClipEvent handler
    trace("hello");

    Scene=Scene 1, Layer=Layer 14, Frame=1: Line 16: Unexpected '}' encountered
    }
    What am I doing wrong? This should be so simple...

  2. #2
    Senior Member
    Join Date
    Apr 2005
    Location
    FL, USA
    Posts
    443
    You can't put on() handlers on components. Use an event listener...
    Code:
    function change() {
    trace("hello");
    }
    comboBox.addEventListener("change" , this);

  3. #3
    The Ancient
    Join Date
    Mar 2000
    Location
    Michigan, USA
    Posts
    213
    Technically, "Change" isn't a mouse event. You don't "change" your mouse button, you click it. Under the covers, the combo box's button has a click event, which changes the selectedItem and dispatches a change event.

    On the timeline that contains the movieclip, you need to create an event listener for your combobox.

    code:
    var listenerObject:Object = new Object();
    listenerObject.change = function(eventObject:Object) {
    // Your code here.
    };
    comboBoxInstance.addEventListener("change", listenerObject)

    jahasloth

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