[Flashcoders] How to set button event listeners within a class
Hey, thanks for checking this. I am writing a class where the onRelease event of the button is handled within the class. This is so I can make a class that can be reused across re-skinned FLAs just by passing the button instance to the class (so I don't need to assign a method of the class to it). I think I may be going about this the wrong way as I am getting lots of error messages in the compiler like: There is no method with the name 'super'. If someone could point me in the right direction here it would be a massive help, I'm worried I may be barking up the wrong tree or trying to do something that isn't possible (or sensible!). Thanks guys and have a good weekend, Ali My class code looks like this: /Send.as import mx.controls.Button; class Send extends XMLSocket { private var sendBtn:Button; function setSendBtn(mySendBtn:Button) { trace(send button received:+mySendBtn) this.sendBtn = mySendBtn; this.sendBtn._visible = false; this.sendBtn.onRelease = function() { trace(-- send pressed ); sendHandler() }; } function sendHandler(){ //send events go here trace(sendHandler called) } } The code in my FLA is: import Send; var mySend:Send = new Send(); mySend.setSendBtn(my_btn) /// ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] How to set button event listeners within a class
You need to use Delegate to keep your scope within the class: import mx.utils.Delegate class MyClass { //stuff private function setActions():Void { myButton.onRelease = Delegate.create(this, myOnRelaseHandler) } private function myOnReleaseHandler():Void { super() } } Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] How to set button event listeners within a class
Use some kind of delegation (e.g. mx.utils.Delegate). (off: using this is not required in AS2 classes) sendBtn.onRelease = mx.utils.Delegate.create(this, sendHandler); Attila ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
RE: [Flashcoders] How to set button event listeners within a class
You would only use super() if you're extending. It sounds like he was using composition, but thinking of inheritance. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Merrill, Jason Sent: Friday, May 18, 2007 11:48 AM To: flashcoders@chattyfig.figleaf.com Subject: RE: [Flashcoders] How to set button event listeners within a class You need to use Delegate to keep your scope within the class: import mx.utils.Delegate class MyClass { //stuff private function setActions():Void { myButton.onRelease = Delegate.create(this, myOnRelaseHandler) } private function myOnReleaseHandler():Void { super() } } Jason Merrill Bank of America GTO Learning Leadership Development eTools Multimedia Team ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] How to set button event listeners within a class
Thanks Merril and Rakos for yr quick responses that is brilliant :) I'll have a shot of this on Monday. Have a great weekend :) Ali On 18 May 2007, at 16:57, Rákos Attila wrote: Use some kind of delegation (e.g. mx.utils.Delegate). (off: using this is not required in AS2 classes) sendBtn.onRelease = mx.utils.Delegate.create(this, sendHandler); Attila ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com