RE: [flexcoders] Re: How to asynchronously dispatch an event
Unless I am missing something... Actually, in the lines: model.addEventListener(eventType, eventListener); var result:MyAsyncToken = model.doAction(...); result.myData = The assignment to result.myData happens before the data service call is invoked, and this will work fine. I believe that call does not happen until the next frame. I would avoid using the word 'result as a variable, and the event type should be ResultEvent. Tracy From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Peter Sent: Friday, March 23, 2007 5:42 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Re: How to asynchronously dispatch an event Thanks for the guidance, and apologies if I am asking very newbie questions. While I have a decent Java background, I do have a lot of new flex/flash things to try and get a grip on. I don't see why you can't use the equivalent of an AsyncToken in a sync call if you really want to. I don't understand the problem. Well, I would like to do something like model.addEventListener(eventType, eventListener); var result:MyAsyncToken = model.doAction(...); result.myData = Unless I am missing something, the problem is that doAction synchronously invokes the eventListener (by invoking dispatchEvent) and therefore the value assigned to result.myData never makes it in the eventListener. There's at least one DoLater.as class floating around in AS2..a doLater is basically just adding an onEnterFrame to an handy MovieClip that calls a given method and then removes itself. I'll try to find what you refer to. Having no flash experience I will have to do a bit of reading to figure out how all this would match up with the scenario above, but it certainly helps me to find the direction to start looking. Much appreciated! Peter
[flexcoders] Re: How to asynchronously dispatch an event
The assignment to result.myData happens before the data service call is invoked, and this will work fine. I believe that call does not happen until the next frame. Yes, exactly. Now the point is (or was really) that I wanted to implement the same api interaction when model.doAction is not asynchronous (doAction here stands for one of a few dozen methods that are implemented on the model object). I naively tried to do that by using dispatchEvent from within the synchronous doAction call, but that did not really get me there because the eventlistener is invoked at the time the dispatchEvent is invoked (beginners mistake I am sure) Anyway, I have decided to turn everything around. After I (finally) realized that using an event dispatching approach for model management calls (sometimes through service invocations) is not really buying me anything, I added the handlers and possible user data, both for the synchronous and asynchronous methods, as arguments to the methods. Although the method signatures get a bit heavy, I like that approach better. It is consisten and it saves me from having to juggle with eventlisteners and an application specific event structure. Of course... I would have preferred everything to be synchronous :) Thanks for you reply, Peter
[flexcoders] Re: How to asynchronously dispatch an event
Ok, I have never really used AsyncToken so I don't really understand the benefits to it. But what would you add to it that would be of any use? Could you not just have an object you pass in the doAction function that is added to the token? That would probably work just as well I guess. I am just exploring the grounds looking for consistency. Besides the extra data one can assign to the token, the fact you can add responders to it also seems an interesting feature. I am still struggling with how to manage event types and event listener's making sure no leaks are introduced or handlers are invoked at the wrong or multiple times. A responder attached to the token would be a possible 'solution', avoiding the need to design an application specific event structure with associated listeners that are added or removed as neededactually what I really could use is synchronous service invocations, but as others have stated introducing me to the flash/flex world: Resistance is futile ... :) Aside from all that, forget about doLater, use callLater, there is plenty of info on callLater in the help. Thanks, that might actually be what I was looking for.
[flexcoders] Re: How to asynchronously dispatch an event
Thanks for your reply Mark Why would it matter for the API whether or not event dispatching was asynchronous? Clients still listen for events and hear them; the only difference would be that the stack would get taller on the sync calls. The main reason is that I want to give the user of the api the ability to add some custom information to the return value of the data model call and make that available in the callback (much like one can add 'stuff' to the AsyncToken returned from e.g. an HTTPService invocation). If you *really* needed to make ape async behavior, you could have the sync methods use a doLater() method to wait a frame before broadcasting an event. Thanks for the doLater() pointer. I can only find info on UIModel.doLater() in the 1.5 docs of flex. Has something changed in 2.0 in that context. Again, I appreciate people taking the time to get be bootstrapped with flex. Peter
[flexcoders] Re: How to asynchronously dispatch an event
You can do this with a timer. There is also an undocumented unsupported class in the rpc package that does this as well, but, *use it at your own risk* import mx.rpc.AsyncDispatcher; new AsyncDispatcher(myEventDispatchMethod, [myEvent], 10); It basically takes a method closure and a list of arguments to pass to that method along with the delay in milliseconds before calling the closure. --- In flexcoders@yahoogroups.com, pgp.coppens [EMAIL PROTECTED] wrote: Thanks for your reply Mark Why would it matter for the API whether or not event dispatching was asynchronous? Clients still listen for events and hear them; the only difference would be that the stack would get taller on the sync calls. The main reason is that I want to give the user of the api the ability to add some custom information to the return value of the data model call and make that available in the callback (much like one can add 'stuff' to the AsyncToken returned from e.g. an HTTPService invocation). If you *really* needed to make ape async behavior, you could have the sync methods use a doLater() method to wait a frame before broadcasting an event. Thanks for the doLater() pointer. I can only find info on UIModel.doLater() in the 1.5 docs of flex. Has something changed in 2.0 in that context. Again, I appreciate people taking the time to get be bootstrapped with flex. Peter
Re: [flexcoders] Re: How to asynchronously dispatch an event
I think doLater is called callLater in AS3 (at least, I see that func occasionally in other people's code). Troy. On 3/23/07, jason_williams_mm [EMAIL PROTECTED] wrote: You can do this with a timer. There is also an undocumented unsupported class in the rpc package that does this as well, but, *use it at your own risk* import mx.rpc.AsyncDispatcher; new AsyncDispatcher(myEventDispatchMethod, [myEvent], 10); It basically takes a method closure and a list of arguments to pass to that method along with the delay in milliseconds before calling the closure. --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com, pgp.coppens [EMAIL PROTECTED] wrote: Thanks for your reply Mark Why would it matter for the API whether or not event dispatching was asynchronous? Clients still listen for events and hear them; the only difference would be that the stack would get taller on the sync calls. The main reason is that I want to give the user of the api the ability to add some custom information to the return value of the data model call and make that available in the callback (much like one can add 'stuff' to the AsyncToken returned from e.g. an HTTPService invocation). If you *really* needed to make ape async behavior, you could have the sync methods use a doLater() method to wait a frame before broadcasting an event. Thanks for the doLater() pointer. I can only find info on UIModel.doLater() in the 1.5 docs of flex. Has something changed in 2.0 in that context. Again, I appreciate people taking the time to get be bootstrapped with flex. Peter
Re: [flexcoders] Re: How to asynchronously dispatch an event
I don't see why you can't use the equivalent of an AsyncToken in a sync call if you really want to. I don't understand the problem. There's at least one DoLater.as class floating around in AS2..a doLater is basically just adding an onEnterFrame to an handy MovieClip that calls a given method and then removes itself. From: pgp.coppens [EMAIL PROTECTED] Date: 2007/03/23 Fri AM 10:54:28 CST To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: How to asynchronously dispatch an event Thanks for your reply Mark Why would it matter for the API whether or not event dispatching was asynchronous? Clients still listen for events and hear them; the only difference would be that the stack would get taller on the sync calls. The main reason is that I want to give the user of the api the ability to add some custom information to the return value of the data model call and make that available in the callback (much like one can add 'stuff' to the AsyncToken returned from e.g. an HTTPService invocation). If you *really* needed to make ape async behavior, you could have the sync methods use a doLater() method to wait a frame before broadcasting an event. Thanks for the doLater() pointer. I can only find info on UIModel.doLater() in the 1.5 docs of flex. Has something changed in 2.0 in that context. Again, I appreciate people taking the time to get be bootstrapped with flex. Peter -- John Mark Hawley The Nilbog Group 773.968.4980 (cell) -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * Your email settings: Individual Email | Traditional * To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) * To change settings via email: mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] * To unsubscribe from this group, send an email to: [EMAIL PROTECTED] * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
RE: [flexcoders] Re: How to asynchronously dispatch an event
Thanks for the guidance, and apologies if I am asking very newbie questions. While I have a decent Java background, I do have a lot of new flex/flash things to try and get a grip on. I don't see why you can't use the equivalent of an AsyncToken in a sync call if you really want to. I don't understand the problem. Well, I would like to do something like model.addEventListener(eventType, eventListener); var result:MyAsyncToken = model.doAction(...); result.myData = Unless I am missing something, the problem is that doAction synchronously invokes the eventListener (by invoking dispatchEvent) and therefore the value assigned to result.myData never makes it in the eventListener. There's at least one DoLater.as class floating around in AS2..a doLater is basically just adding an onEnterFrame to an handy MovieClip that calls a given method and then removes itself. I'll try to find what you refer to. Having no flash experience I will have to do a bit of reading to figure out how all this would match up with the scenario above, but it certainly helps me to find the direction to start looking. Much appreciated! Peter
[flexcoders] Re: How to asynchronously dispatch an event
Ok, I have never really used AsyncToken so I don't really understand the benefits to it. But what would you add to it that would be of any use? Could you not just have an object you pass in the doAction function that is added to the token? I suppose it's all the things I can't think of that make it useful. Aside from all that, forget about doLater, use callLater, there is plenty of info on callLater in the help. Paul --- In flexcoders@yahoogroups.com, Peter [EMAIL PROTECTED] wrote: Thanks for the guidance, and apologies if I am asking very newbie questions. While I have a decent Java background, I do have a lot of new flex/flash things to try and get a grip on. I don't see why you can't use the equivalent of an AsyncToken in a sync call if you really want to. I don't understand the problem. Well, I would like to do something like model.addEventListener(eventType, eventListener); var result:MyAsyncToken = model.doAction(...); result.myData = Unless I am missing something, the problem is that doAction synchronously invokes the eventListener (by invoking dispatchEvent) and therefore the value assigned to result.myData never makes it in the eventListener. There's at least one DoLater.as class floating around in AS2..a doLater is basically just adding an onEnterFrame to an handy MovieClip that calls a given method and then removes itself. I'll try to find what you refer to. Having no flash experience I will have to do a bit of reading to figure out how all this would match up with the scenario above, but it certainly helps me to find the direction to start looking. Much appreciated! Peter