RE: [Flashcoders] dispatching events from a class = HELP
Hi, I'm also having problems with Events. Could someone give me a little help on this issue? The EventListener is firing fine, but its associated method CAN NOT call another Class method. Why? Here is the Main Class: (Here is the Problem) import com.ultrafactor.LblButton; class com.ultrafactor.TabBox extends MovieClip { private var tab_0:LblButton; public function TabBox() { main(); } private function main():Void { setButtonListeners(); } // don't know why it takes so long... // is there any other elegant way to do it?? private function setButtonListeners():Void { i=0; this.onEnterFrame = function() { this.i++; if(this.i==20) { delete this.onEnterFrame; } else { tab_0.addEventListener(release,this.clickTab); } } } private function clickTab(evtObj:Object):Void { trace(click);// WORK this.test();// DO NOT WORK } //Can't call this Method!!! private function test():Void { trace(test); } } The used Classes: import mx.core.UIObject; import mx.core.UIComponent; class com.ultrafactor.Button extends mx.core.UIComponent { private var initializing:Boolean = true; private var autoRepeat:Boolean; private var interval; function Button() { super.init(); useHandCursor = true; } private function size(Void):Void { super.invalidate(); } private function draw(Void):Void { if (initializing) { initializing = false; } size(); } private function onRollOver():Void { if (interval != undefined) { clearInterval(interval); delete interval; } gotoAndStop(2); } private function onDragOver():Void { onPress(); } private function onRollOut():Void { gotoAndStop(1); } private function onDragOut():Void { onRollOut(); } private function onRelease():Void { dispatchEvent({type:click}); onRollOver(); } private function onPress():Void { gotoAndStop(3); dispatchEvent({type:buttonDown}); if (autoRepeat) { interval = setInterval(this, onPressDelay, getStyle(repeatDelay)); } } private function onPressDelay(Void):Void { dispatchEvent({type:buttonDown}); if (autoRepeat) { clearInterval(interval); interval = setInterval(this, onPressRepeat, getStyle(repeatInterval)); } } private function onPressRepeat(Void):Void { dispatchEvent({type:buttonDown}); updateAfterEvent(); } } import com.ultrafactor.Button; import mx.core.UIObject; import mx.core.UIComponent; import mx.events.EventDispatcher; class com.ultrafactor.LblButton extends Button { private function dispatchEvent() {}; public function addEventListener() {}; public function removeEventListener() {}; private var lbl:TextField; private var link:String; private var initializing:Boolean = true; private var initText:String; function LblButton() { mx.events.EventDispatcher.initialize(this); super.init(); } public function setLabel(t:String):Void { if (initializing) { initText = t; } else { lbl.embedFonts = true; lbl.text = t; invalidate(); } draw(); } public function getLabel():String { if (initializing) return initText; return lbl.text; } public function
Re: [Flashcoders] dispatching events from a class = HELP
You need to use a Delegate. As this is a question which comes up about one a week on this mailing list (not your, fault, I know!) I'm afraid I'm going to direct you to the Flashcoders Wiki page about the problem rather than answer you in full here... http://www.osflash.org/flashcoders/as2 Hope that helps, Ian On 11/13/05, Bruno Mosconi [EMAIL PROTECTED] wrote: Hi, I'm also having problems with Events. Could someone give me a little help on this issue? The EventListener is firing fine, but its associated method CAN NOT call another Class method. Why? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] dispatching events from a class = HELP
Why delegate if the method is inside the same Class? thanks -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas Sent: domingo, 13 de novembro de 2005 15:46 To: Flashcoders mailing list Subject: Re: [Flashcoders] dispatching events from a class = HELP You need to use a Delegate. As this is a question which comes up about one a week on this mailing list (not your, fault, I know!) I'm afraid I'm going to direct you to the Flashcoders Wiki page about the problem rather than answer you in full here... http://www.osflash.org/flashcoders/as2 Hope that helps, Ian On 11/13/05, Bruno Mosconi [EMAIL PROTECTED] wrote: Hi, I'm also having problems with Events. Could someone give me a little help on this issue? The EventListener is firing fine, but its associated method CAN NOT call another Class method. Why? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] dispatching events from a class = HELP
You need to use the Delegate in your addEventListener line - because you're passing clickTab to a completely different object, which will later call back to clickTab, but doesn't have the correct context. Passing this.clickTab isn't enough - passing Delegate.create(this,clickTab) should be enough. I know it's odd. This is changed in AS3. Ian On 11/13/05, Bruno Mosconi [EMAIL PROTECTED] wrote: Why delegate if the method is inside the same Class? thanks ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] dispatching events from a class = HELP
Thanks! Btw, AS 3.0 looks like AS 2.0 FIXED... -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas Sent: domingo, 13 de novembro de 2005 16:25 To: Flashcoders mailing list Subject: Re: [Flashcoders] dispatching events from a class = HELP You need to use the Delegate in your addEventListener line - because you're passing clickTab to a completely different object, which will later call back to clickTab, but doesn't have the correct context. Passing this.clickTab isn't enough - passing Delegate.create(this,clickTab) should be enough. I know it's odd. This is changed in AS3. Ian On 11/13/05, Bruno Mosconi [EMAIL PROTECTED] wrote: Why delegate if the method is inside the same Class? thanks ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders