user-interfaceeventsapache-flexflex4flex-spark

Flex: Programmatically firing event listeners


I would like to programmatically fire an event on a spark checkbox.

I have a tab bar which has tabs enabled according to various checkboxes. I am loading data into these tabs. Sometimes tabs 1 and 2 will be enabled. Other times tabs 2 and 3. Other times tab 4 by itself (and all the other combinations).

I have tried to enable the VBox (in action script) which is in my view stack but it seems to freeze the application. The VBox enables correctly upon user input on the check box. If I set the checkbox to be selected it does not fire the event and so does not enable the tab. Is it possible to manually fire an event in Flex. I have tried to see if I can take the checkbox and get the event and fire it. Unfortunately I can only see addEventListener, hasEventLister and removeEventListener. There is no way of getting the events that are already on the checkbox


Solution

  • To dispatch and event from a component:

    component.dispatchEvent(event)

    Example:

    var evt:MouseEvent=new MouseEvent(MouseEvent.CLICK)

    this.checkBox.dispatchEvent(evt)

    it doesn't put the selecte mark but you could set it programmaticaly with this.checkBox.selected=true