Flex 3 - Actionscript - Cairngorm Dispatchevents - How to know when the event is over?

Asked

Viewed 109 times

2

I’m using Flex 3 with Cairngorm framework. Somewhere in the program I trigger an event dispatchEvent, as:

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

Is there any way to know when the event ended? That’s 100%?

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

1 answer

0


Usually when dispatching a new event from an object the only listener who listens to 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 above example, I add a function that runs only when all my code is ready and dispatched with the event called "CONTADOR_10".

I don’t have much knowledge of this library, but I’ve noticed that it possesses the addEventListener, responsible for adding event listener to the object CairngormEventDispatcher.getInstance().

Try adding your code to the listener function:

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

Remembering that whenever added a listener and this will no longer be used, one should remove it with the removeEventListener.

  • biio really, adding the addeventlistener it waits until it is completed. And what happened was, on the first call, he doesn’t even go into the Istener and he doesn’t do anything, just from the second call. What I did to solve for those who have the same problem is to put my logic that was after the call in the Command result() function. Whoever uses this framework will know where it is. Thanks for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.