PDA

View Full Version : Synchronous Event Flow



rfkrocktk
June 24th, 2009, 06:00 PM
Is there a way to make event flow occur synchronously?

Basically this is my scenario. I have a single method call that gets triggered by a server request. I want to be able to notifiy subscribers that the method has/is executing so that they may return a result. By modifying an attribute of the actual event object, the method can return that result to the server dynamically. Eg:

//method invoked by server
public function whatever(...parameters):* {
var event:MyEvent = new MyEvent(MyEvent.TYPE);
dispatchEvent(event);

return event.returnValue;
}

//subscriber to this event
private function onWhatever(e:MyEvent):void {
e.returnValue = "hellow";
}

This code works around 70% of the time, but sometimes I see things are really happening asynchronously in Flash Player's event flow. Is there anything I can do to regulate this and make sure it happens synchronously?

BoppreH
June 24th, 2009, 06:24 PM
I'm not very aware of flash's inner workings, but there is probably a "get listeners" function somewhere.

You could use a timer too. It's not very elegant, but works.

rfkrocktk
June 24th, 2009, 06:38 PM
I can't seem to find a way to get access to a set of listeners at all. The problem is that I need to do this completely synchronously, I can't even call "setTimeout" or use a timer to get around this limitation. The reason is that the server expects to call a method on my NetConnection and have that method call return a value. If I need to devise another way to make this happen synchronously, then I will, but I just wanted to know if there was something I'm missing here.

Does anyone else have any suggestions on things to try?

senocular
June 24th, 2009, 06:42 PM
listeners are inaccessible. Events are synchronous. Retrieving remote data is not.

rfkrocktk
June 24th, 2009, 07:10 PM
senocular, thanks!
It turned out that my own flow was wrong. The result was getting returned to the server synchronously in the fashion I wanted, but the problem was that sometimes my connection would be closed before the server could process the result which I returned, making it look as if the client had failed to do something.

It's good to know that event dispatching is done synchronously and not asynchronously :)