Flex 3 - ActionScript - Cairngorm DispatchEvents - How do I know when event is over?

2

I'm using Flex 3 with Cairngorm framework. Somewhere in the program I trigger a dispatchEvent event, like:

CairngormEventDispatcher.getInstance().dispatchEvent(new eventExample [...]

Do you have any way to tell when the event is over? What is 100%?

Because I have other things after that call that depend on the return of that event. For example, an arrayCollection of items that return from the base with this call. But in the first call that is in a popWindow it returns null because it did not end the event yet and I end up using the array for other things .. When I open the screen again there is the data.     

asked by anonymous 26.06.2014 / 13:27

1 answer

0

Normally when dispatching a new event from an object the only listener that hears this event is added to the object itself.

Example in Flash:

var objeto:MovieClip = new MovieClip(); //Cria o objeto
objeto.addEventListener("CONTADOR_10", funcaoOuvinte); //Adiciona um ouvinte ao objeto

var contador:int = 0;
for(var i:int = 0; i <= 10; i++) {
    contador++;
    trace(contador);
    if(contador == 10) {
        objeto.dispatchEvent(new Event("CONTADOR_10", false, false)); //Despacha um novo evento chamado "CONTADOR_10";
        break;
    }
}

function funcaoOuvinte(e:Event):void {
     trace("Evento concluído/escutado com sucesso!");
}

In the example above, I add a function that is executed only when all my code is ready and dispatched with the event called "COUNTER_10".

I do not know much about this library, but I noticed that it has addEventListener , which is responsible for adding event listener to the CairngormEventDispatcher.getInstance() object.

Try adding your code to the listener function:

CairngormEventDispatcher.getInstance().addEventListener("SEU_EVENTO", function():void {
    trace("Evento concluído");
}

Remembering that whenever a listener is added and it will no longer be used, it should be removed with removeEventListener .

    
30.06.2014 / 15:13