tag:blogger.com,1999:blog-2494368992571633003.post976076234522637802..comments2023-03-20T05:21:07.556-07:00Comments on I am Prashant Jain: Removing mxml/inline event listenersPrashant Jainhttp://www.blogger.com/profile/07377369194623376447noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-2494368992571633003.post-88342186365988057712010-12-02T15:46:17.191-08:002010-12-02T15:46:17.191-08:00Another alternative is to create a function that a...Another alternative is to create a function that adds all of your event listeners programmatically on init of the mxml, so it would look something like this<br /><br /><mx:Button initialize="addEventListeners(event)"/><br /><br />private function addEventListeners(event:FlexEvent):void<br />{<br /> event.currentTarget.addEventListener(MouseEvent.CLICK, onMouseClick);<br /> event.currentTarget.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);<br /> // ... etc.<br />}schjlatahhttp://blakebarrett.netnoreply@blogger.comtag:blogger.com,1999:blog-2494368992571633003.post-80965481934757233492010-09-09T08:18:19.622-07:002010-09-09T08:18:19.622-07:00Simple workaround:
If you know ahead of time that...Simple workaround:<br /><br />If you know ahead of time that you'll have to kill an event, and you have control of the mxml, then make a smart listener that checks for a global flag (such as a custom settings object on the Application singleton). If the flag is off, then the listener won't do its intended work when fired.<br /><br />var appSettings:ApplicationSettings; //*ALWAYS* cast your custom objects to a defined class type.<br />...<br /><mx:Button click="if (Application.application.appSettings.buttonEventAllowed) onClick(event)"/>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-2494368992571633003.post-34076495801333853732010-06-17T18:21:13.833-07:002010-06-17T18:21:13.833-07:00Hi Prashant,
Can you provide some sample code for...Hi Prashant,<br /><br />Can you provide some sample code for displaying the custom component in the actionscript repeater.. bcoz.. I facing some issue in displaying the custom component in a VBox container through the Repeater.<br /><br />Thanks in advance.<br /><br />-Ven.ven512https://www.blogger.com/profile/09817712068957165437noreply@blogger.comtag:blogger.com,1999:blog-2494368992571633003.post-21819284776224519222010-03-29T07:33:26.236-07:002010-03-29T07:33:26.236-07:00SudnilD/Ike,
As promised, the source code and expl...SudnilD/Ike,<br />As promised, the source code and explanation is all here. Let me know if you have any questions.<br /><br />PrashantPrashant Jainhttps://www.blogger.com/profile/07377369194623376447noreply@blogger.comtag:blogger.com,1999:blog-2494368992571633003.post-63868667811967592052010-03-26T19:07:34.295-07:002010-03-26T19:07:34.295-07:00Just haven't had time from my busy schedule to...Just haven't had time from my busy schedule to post the solution and the source code. But I promise you will have a solution by eod tomorrow.<br /><br />PrashantPrashant Jainhttps://www.blogger.com/profile/07377369194623376447noreply@blogger.comtag:blogger.com,1999:blog-2494368992571633003.post-20197013917224355172010-03-26T16:40:16.438-07:002010-03-26T16:40:16.438-07:00oops, got the syntax slightly wrong above, but you...oops, got the syntax slightly wrong above, but you get the idea :Psunildhttps://www.blogger.com/profile/07572946298935026191noreply@blogger.comtag:blogger.com,1999:blog-2494368992571633003.post-53908699538951492492010-03-26T16:37:57.116-07:002010-03-26T16:37:57.116-07:00Hi Prashant, good to see that you're blogging!...Hi Prashant, good to see that you're blogging!<br /><br />I don't think there is a way to remove inline event listeners. I haven't dug into the generated code that deeply.<br /><br />A similar problem to this is to remove a listener when the listener is an anonymous function. The solution here is to use the arguments object that is accessible inside every function. You can use arguments.callee to get a reference to the listener function and remove it:<br /><br />this.addEventListener(MouseEvent.CLICK,<br /> function {<br /> this.removeEventListener(MouseEvent.CLICK, arguments.callee);<br /> // normal listener code here<br /> } );<br /><br />But if you try to use arguments.callee to remove an inline event listener, it doesn't work :(<br /><br />Please do share if you find a solution to this!sunildhttps://www.blogger.com/profile/07572946298935026191noreply@blogger.comtag:blogger.com,1999:blog-2494368992571633003.post-62923791714297351922010-03-26T00:20:53.545-07:002010-03-26T00:20:53.545-07:00Hey Pj
Really nice stuff, and very eager to know ...Hey Pj<br /><br />Really nice stuff, and very eager to know a solution on this.<br /><br />working hard to get one.<br /><br />But found a work around adding a <br /><br />button.addEventlistener(mouseEvent.click, buttonOnClick);<br /><br />on the code will not create the inline functions<br /><br />Thanks<br /><br />IKEIke Blogshttps://www.blogger.com/profile/13743757972607058534noreply@blogger.com