[Flashcoders] Question regarding use of Delegate in a class
Good evening people, I asked this on the newbie list since I suspect it to be a newbie question,, but didn't get an answerso I hope to find the answer here: I have some code in a class that needs to fire a fuction (startTimer) from an onEnterFrame eventi can fire it from an onrelease usung Delegate, but not from the onEnterFrame..what am I missing here? code private function doFade():Void{ container_mc.onEnterFrame = function(){ this.fader_mc._alpha-=faderSpeed; if(this.fader_mc._alpha = 0){ this.fader_mc._alpha=0; Delegate.create(this, startTimer); -- DOESN'T WORK delete this.onEnterFrame; } } container_mc.onRelease = Delegate.create(this, startTimer); -- WORKS AND FIRES THE FUNCTION WHEN I CLICK THE MOVIECLIP } /code Thx for your help, Wout ___ 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] Question regarding use of Delegate in a class
Hi Wouter, Delegate.create() doesn't _call_ a function, it just creates a Function variable for later use. Which is like a reference to a function. By calling: container_mc.onRelease = Delegate.create(this, startTimer); You're saying, in effect when onRelease is called, trigger the code in startTimer. By saying: Delegate.create(this, startTimer); in your doFade() function, you're just creating a function reference and not storing the value anywhere - not doing anything with it. What you actually want to do is to call the function, which you should be able to do with: this.startTimer(); or even startTimer(); HTH, Ian On 2/21/06, Wouter Steidl [EMAIL PROTECTED] wrote: Good evening people, I asked this on the newbie list since I suspect it to be a newbie question,, but didn't get an answerso I hope to find the answer here: I have some code in a class that needs to fire a fuction (startTimer) from an onEnterFrame eventi can fire it from an onrelease usung Delegate, but not from the onEnterFrame..what am I missing here? code private function doFade():Void{ container_mc.onEnterFrame = function(){ this.fader_mc._alpha-=faderSpeed; if(this.fader_mc._alpha = 0){ this.fader_mc._alpha=0; Delegate.create(this, startTimer); -- DOESN'T WORK delete this.onEnterFrame; } } container_mc.onRelease = Delegate.create(this, startTimer); -- WORKS AND FIRES THE FUNCTION WHEN I CLICK THE MOVIECLIP } /code Thx for your help, Wout ___ 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] Question regarding use of Delegate in a class
Oops - would help if I read your code properly! The first bit of my reply made sense - you're not _calling_ the function, just creating a reference to it. Calling this.startTimer() won't work because you're in an inner function. startTimer() should do it. Ian ___ 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] Question regarding use of Delegate in a class
There is another way of doing it as well, FYI, that doesn't use the delegate class. You can take advantage of the fact that handler functions can see local variables and use a local variable to make reference to the class. The line: var parent = this; (or fully typed, var parent:MyClassName = this;) allows you to store a reference to the class instance. You can then reference any method or property by just calling parent.methodName() or parent.propertyName from within your handler functions. private function doFade():Void{ var parent = this; container_mc.onEnterFrame = function(){ this.fader_mc._alpha-=faderSpeed; if(this.fader_mc._alpha = 0){ this.fader_mc._alpha=0; parent.startTimer(); delete this.onEnterFrame; } } container_mc.onRelease = function() { parent.startTimer(); } } Nathan http://www.nathanderksen.com On Feb 21, 2006, at 9:40 AM, Wouter Steidl wrote: private function doFade():Void{ container_mc.onEnterFrame = function(){ this.fader_mc._alpha-=faderSpeed; if(this.fader_mc._alpha = 0){ this.fader_mc._alpha=0; Delegate.create(this, startTimer); -- DOESN'T WORK delete this.onEnterFrame; } } container_mc.onRelease = Delegate.create(this, startTimer); -- ___ 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