I'm using the combobox component and I want to manually dispatch the "change" event. How is this done?
// Dispatches when user changes selection
comboType.addEventListener("change开发者_运维问答",cbListenerDialogue);
// Does not manually dispatch
comboType.dispatchEvent("change");
comboType.dispatchEvent(new Event("change"));
The string value you use for the dispatch has to match what's already defined in Flash.
This should to the trick.
comboType.dispatchEvent(new Event(Event.CHANGE, true));
Also: AS3 Textbox Change Event Not Firing
Just to be clear,
comboType.dispatchEvent(new Event(Event.CHANGE, true));
works because bubbling is set to "true".
For example,
comboType.addEventListener("change",cbListenerDialogue);
comboType.dispatchEvent(new Event("change", true));
would work too. The important thing is that non mouse events won't propagate (bubble) unless set to true as Event.CHANGE and "change" are the same thing.
精彩评论