tag:blogger.com,1999:blog-5350157389434430698.post8653741920387206626..comments2024-02-27T21:23:44.159-08:00Comments on A Three-Pound Monkey Brain: How to Extend "Event", Once and For AllMike Keeseyhttp://www.blogger.com/profile/00147156174467903264noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-5350157389434430698.post-10076782336947059532012-03-06T16:39:41.138-08:002012-03-06T16:39:41.138-08:00Nice exampleNice exampleAnonymoushttps://www.blogger.com/profile/13535077415613652922noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-30603109687173655762008-07-10T08:27:00.000-07:002008-07-10T08:27:00.000-07:00Heh, no problem.I've been with Flasha long time. T...Heh, no problem.<BR/><BR/>I've been with Flasha long time. The current version is ... well, let's just say it's going through growing pains. (Which is why I mostly use Flex now.)Mike Keeseyhttps://www.blogger.com/profile/00147156174467903264noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-44932411890773040392008-07-10T04:14:00.000-07:002008-07-10T04:14:00.000-07:00thanks so much. flash is a lumbering hulking arse ...thanks so much. flash is a lumbering hulking arse of a program designed by a team of sadistic monkeys with a depressingly effective marketing department, and what's more the manual is so crap (and online, so unsearchable) that random forum posts show up before pages on adobe.com when you google search.<BR/><BR/>posts like this help to make us poor developers lives just that little bit less painful..Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-57295937940154691702008-06-16T09:24:00.000-07:002008-06-16T09:24:00.000-07:00Actually, yes, I had just noticed that and was goi...Actually, yes, I had just noticed that and was going to update the post at some point. It's a bug in Flex Builder, and it's in their public bug database. Hopefully it'll be fixed in the next version.Mike Keeseyhttps://www.blogger.com/profile/00147156174467903264noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-15903109954572792802008-06-16T08:24:00.000-07:002008-06-16T08:24:00.000-07:00Great summary, Mike. I wonder whether you also see...Great summary, Mike. I wonder whether you also see a bug in Flex Builder 3 for your tip #5: Code completion does not show ProcessController.EVENT_START but Event.START . If it's really a bug, it makes metadata in this scenario somewhat useless.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-33040439590006961952008-03-06T08:37:00.000-08:002008-03-06T08:37:00.000-08:00Whoops -- I forgot that AsyncToken doesn't actuall...Whoops -- I forgot that <I>AsyncToken</I> doesn't actually dispatch<I>ResultEvent</I> objects, but just passes them (and <I>FaultEvent</I> objects) on to <I>Responder</I> objects. Well, glad it's working now!Mike Keeseyhttps://www.blogger.com/profile/00147156174467903264noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-65189635979064993452008-03-06T07:06:00.000-08:002008-03-06T07:06:00.000-08:00OMG, you have shed the light on my problem :).publ...OMG, you have shed the light on my problem :).<BR/><BR/>public function count():void<BR/> {<BR/> var query:String = "lastname like '%prac%'";<BR/> var token:AsyncToken = WS.count("Patient", "", query);<BR/> token.query = query;<BR/> var responder:mx.rpc.Responder = new mx.rpc.Responder( onResult, faultHandler );<BR/> token.addResponder(responder); <BR/> }<BR/> <BR/> private function onResult(event:ResultEvent):void <BR/> {<BR/> var data:Object = event.result;<BR/> var query:String = event.token.query;<BR/> // Perform another call with same query.<BR/> }<BR/><BR/>Thank you very much!Nealio42https://www.blogger.com/profile/00817688824376421335noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-76399828113382800452008-03-05T13:40:00.000-08:002008-03-05T13:40:00.000-08:00No problem. (I've never actually tried it, so let ...No problem. (I've never actually tried it, so let me now if it works!)Mike Keeseyhttps://www.blogger.com/profile/00147156174467903264noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-37899751233214324192008-03-05T13:13:00.000-08:002008-03-05T13:13:00.000-08:00very cool, I will try that. Thank you for taking t...very cool, I will try that. Thank you for taking the time to answer the question.Nealio42https://www.blogger.com/profile/00817688824376421335noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-85477750299602679942008-03-04T10:52:00.000-08:002008-03-04T10:52:00.000-08:00That approach isn't going to work unless you exten...That approach isn't going to work unless you extend <I>WebService</I> to dispatch your type of event rather than (or along with) <I>ResultEvent</I> objects.<BR/><BR/>A better approach would involve using the <I>AsyncToken</I> object generated by the request. <I>AsyncToken</I> is a dynamic class, so you can add custom data to it:<BR/><BR/>In the invoking method:<BR/><I>var query:String<BR/> = "lastname like %smith%";<BR/>var token:AsyncToken<BR/> = WS.count("Person", query);<BR/>token.query = query;<BR/>token.addEventListener(<BR/> ResultEvent.RESULT,<BR/> onResult);<BR/></I><BR/><BR/>And the handler:<BR/><I>private function onResult(event:ResultEvent):void {<BR/>var data:Object<BR/> = event.result;<BR/>var query:String<BR/> = AsyncToken(event.target).query;<BR/>// Perform another call with same query.<BR/>}</I>Mike Keeseyhttps://www.blogger.com/profile/00147156174467903264noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-83421572057993751092008-03-04T06:45:00.000-08:002008-03-04T06:45:00.000-08:00Hi thanks for responding. The webservice that I'm ...Hi thanks for responding. The webservice that I'm calling has a count method that returns the total number of rows for a particular object.<BR/><BR/>WS.count(whatObj, "query");<BR/><BR/>a real example whould look like <BR/><BR/>WS.count("Patient", "lastname like '%smith%'");<BR/><BR/>the count returns 694 rows. I then on that result want to use that same query to call another method that gives me the rows.<BR/><BR/>WS.find("Patient", "lastname like '%smith%'");<BR/><BR/>So I need to pass the query to the resultEvent as an additional param.<BR/><BR/>addEventListener("result", resultHander(query));<BR/><BR/>will not work. So I tried to subClass the resultEvent.<BR/><BR/>I hope this makes sense. I actually thought that the webservice should provide more information (the query used) about the the returned data, other than just the data itself (694 rows) or combine the methods into one and give me a count and the results.Nealio42https://www.blogger.com/profile/00817688824376421335noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-37627995758622832772008-03-03T20:20:00.000-08:002008-03-03T20:20:00.000-08:00Oh, also:package flex.eventsThat's Adobe's namespa...Oh, also:<BR/><BR/><I>package flex.events</I><BR/><BR/>That's Adobe's namespace. You should make your own, or it might conflict with Adobe code. (So far Adobe only has Java code in its <I>flex</I> family of packages, I think, but that could change.) Most people just take their web address and invert it, which is a good ploy. I work with <I>com.exopolis</I>, <I>org.marchofman</I>, <I>org.namesonnexus</I>, <I>com.dinosauricon</I>, etc. and I can be pretty confident my packages won't ever conflict with anybody else's.Mike Keeseyhttps://www.blogger.com/profile/00147156174467903264noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-72076811694828748852008-03-03T20:15:00.000-08:002008-03-03T20:15:00.000-08:00I'm surprised it compiles with the superclass cons...I'm surprised it compiles with the superclass constructor call as the <B>second</B> line of the constructor (it should be the first line), but it looks fine otherwise. I think your problem is in knowing where to substitute the <I>ResultEvent</I> created by the web service with your own custom event. You could try something like this in your <I>DxController</I> class:<BR/><BR/><I>public function addWebService(ws:WebService):void {<BR/>ws.GetInfoByCity.addEventListener( ResultEvent.RESULT, onWebServiceResult);<BR/>}<BR/><BR/>private function onWebServiceResult(event:ResultEvent):void {<BR/>_data = event.result as String;<BR/>dispatchEvent(new DxEvent(DxEvent.RES, data, event.result, event.bubbles, event.cancelable));<BR/>}</I><BR/><BR/>You'll notice, though, that that's completely redundant. The <I>data</I> and <I>result</I> fields will be exactly the same. Which makes me want to ask--why are you extending <I>ResultEvent</I> at all? What difference is there between its <I>result</I> and your <I>data</I>?Mike Keeseyhttps://www.blogger.com/profile/00147156174467903264noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-71308196257879962892008-03-03T18:59:00.000-08:002008-03-03T18:59:00.000-08:00DxEvent.aspackage flex.events{ import flash.events...DxEvent.as<BR/>package flex.events<BR/>{<BR/> import flash.events.Event;<BR/> <BR/> import mx.rpc.events.ResultEvent;<BR/> <BR/> public class DxEvent extends ResultEvent<BR/> {<BR/> public function DxEvent(type:String, data:String, result:Object = null, bubbles:Boolean = false, cancelable:Boolean = false)<BR/> {<BR/> _data = data;<BR/> super(type, result, bubbles, cancelable);<BR/> }<BR/> <BR/> public static const RES:String = "res";<BR/> private var _data:String;<BR/> <BR/> public function get data():String<BR/> {<BR/> return _data;<BR/> }<BR/> override public function clone():Event<BR/> {<BR/> return new DxEvent(type, data, result, bubbles, cancelable);<BR/> }<BR/> }<BR/>}<BR/><BR/>DxController.as<BR/>package flex.events<BR/>{<BR/> import flash.events.EventDispatcher;<BR/> <BR/> [Event(name="res", type="flex.events.DxEvent")]<BR/> <BR/> public class DxController extends EventDispatcher<BR/> {<BR/> public function DxController()<BR/> {<BR/> super();<BR/> }<BR/> <BR/> private var _data:String;<BR/> <BR/> [Bindable(event="res")]<BR/> public function get data():String<BR/> {<BR/> return _data;<BR/> }<BR/> public function set data(value:String):void<BR/> {<BR/> _data = value;<BR/> dispatchEvent(new DxEvent(DxEvent.RES, value));<BR/> }<BR/><BR/><BR/> }<BR/>}<BR/><BR/>I then have a function that uses a webservice<BR/>CursorManager.setBusyCursor();<BR/> WS = new WebService();<BR/> WS.wsdl = "http://www.webservicex.net/uszip.asmx?wsdl"<BR/> WS.GetInfoByCity.resultFormat = "e4x";<BR/> WS.GetInfoByCity.addEventListener("fault", faultHandler);<BR/> WS.GetInfoByCity.addEventListener("res", customlistener);<BR/> WS.addEventListener(LoadEvent.LOAD, loadHandler);<BR/> WS.loadWSDL();<BR/><BR/>I'm not sure how or where to dispatch the DxEvent. Do I dispatch it in the loadHandler? <BR/><BR/>thanks for your help!<BR/>NealNealio42https://www.blogger.com/profile/00817688824376421335noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-58567903568017491102008-03-03T13:51:00.000-08:002008-03-03T13:51:00.000-08:00I'd have to see your code to be sure, but make sur...I'd have to see your code to be sure, but make sure you're passing the <I>result</I> object to the super constructor (i.e., the <I>ResultEvent</I> constructor) . That's the only way you can set <I>ResultEvent.result</I>.Mike Keeseyhttps://www.blogger.com/profile/00147156174467903264noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-36741109204698793312008-03-03T13:46:00.000-08:002008-03-03T13:46:00.000-08:00Great example!I'm trying to create a custom Result...Great example!<BR/><BR/>I'm trying to create a custom ResultEvent. I need to pass it additional parameters like you did in the example.<BR/><BR/>So instead of extending Event, I extended ResultEvent.<BR/><BR/>If I manually dispatch the event, i only get the passed parameter and not the result. Any idea what I'm forgetting?Nealio42https://www.blogger.com/profile/00817688824376421335noreply@blogger.comtag:blogger.com,1999:blog-5350157389434430698.post-79214731734303644292008-01-21T18:19:00.000-08:002008-01-21T18:19:00.000-08:00I admire all those who have the patience to learn ...I admire all those who have the patience to learn programming.Anonymousnoreply@blogger.com