Re: [Flashcoders] |:::| can you write dynamic meathods in a class?
If you're already using a custom Delegate, why not modify the thing to handle what you've just provided? var clickHandler:Function = MyClass.staticMethod; var args:Array = ['Can', 'pass', 'in', 'any', 'amount']; newBtn.addEventListener("click", Delegate.create2(this, clickHandler, args )); // (I'm sure you could think of a better name than 'create2' though) that's all a Delegate is doing is an apply. It's not magic, not really. Tyler On 8/13/06, Bjorn Schultheiss <[EMAIL PROTECTED]> wrote: Hey Guys, check this out Var clickHandler:Function = MyClass.staticMethod; var args:Array = ['Can', 'pass', 'in', 'any', 'amount']; newBtn.addEventListener("click", Delegate.create(this, function(evt:Object, meth:Function, args:Array) { meth.apply(null, args) }, clickHandler, args ) ); Regards, Bjorn Schultheiss Senior Flash Developer QDC Technologies -Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of dnk Sent: Monday, 14 August 2006 5:17 AM To: Flashcoders mailing list Subject: Re: [Flashcoders] |:::| can you write dynamic meathods in a class? Ramon Miguel M. Tayag wrote: > Sometimes some events pass their own args and you dont even see them.. > > Try changing your function to this: > > function onHit1(o:Object, n:Number) //the o object is passed by the > listener { >trace("it was hit with the number: " + n); } > That worked perfect!!! Thanks sooo much! d ___ 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 ___ 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] |:::| can you write dynamic meathods in a class?
If I want to change the behavior of an object dynamically I rather create a new class to encapsulate the functionality. I might have to write more code but I think it this is a very clean approach. class CustomClickBehavior implements Clickable { public function click():Void { trace ("hello world!"); } } // class class Foo { var myClickBehavior: Clickable; // here I can change the behavior to what ever I want public function setClickBehavior (myClickBehavior: Clickable):Void { this. myClickBehavior = myClickBehavior; } public function onClick():Void { myClickBehavior.click(); } } // Interface Interface Clickable { public function click():void; } // code var myFoo = new Foo(); var myCustomClickBehavior = new CustomClickBehavior(); myFoo.setClickBehavior(myCustomClickBehavior); -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of dnk Sent: Monday, 14 August 2006 1:47 PM To: Flashcoders mailing list Subject: Re: [Flashcoders] |:::| can you write dynamic meathods in a class? Bjorn Schultheiss wrote: > Hey Guys, check this out > > > Var clickHandler:Function = MyClass.staticMethod; > var args:Array = ['Can', 'pass', 'in', 'any', 'amount']; > newBtn.addEventListener("click", Delegate.create(this, function(evt:Object, > meth:Function, args:Array) { meth.apply(null, args) }, clickHandler, args ) > ); That is a good idea! I just tried one of simpler layout (at least to me in terms of what I understand in AS) works like a charm: import utils.Delegate; //Create array to pass multiple args in - both string and number for testing var aMyArgs:Array = [1, 2, 'three', 4]; //use the delegate this.menuBtn.addEventListener("click", Delegate.create(this, onHit1, aMyArgs)); //create the btn event to handle the click function onHit1(o:Object, n:Array) { for (i = 0; i < n.length; i++) { trace("it was hit with the arg: " + n[i]); } } This is VERY handy (well to me anyways) to be able to pass in what ever args I need to. d ___ 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] |:::| can you write dynamic meathods in a class?
Bjorn Schultheiss wrote: Hey Guys, check this out Var clickHandler:Function = MyClass.staticMethod; var args:Array = ['Can', 'pass', 'in', 'any', 'amount']; newBtn.addEventListener("click", Delegate.create(this, function(evt:Object, meth:Function, args:Array) { meth.apply(null, args) }, clickHandler, args ) ); That is a good idea! I just tried one of simpler layout (at least to me in terms of what I understand in AS) works like a charm: import utils.Delegate; //Create array to pass multiple args in - both string and number for testing var aMyArgs:Array = [1, 2, 'three', 4]; //use the delegate this.menuBtn.addEventListener("click", Delegate.create(this, onHit1, aMyArgs)); //create the btn event to handle the click function onHit1(o:Object, n:Array) { for (i = 0; i < n.length; i++) { trace("it was hit with the arg: " + n[i]); } } This is VERY handy (well to me anyways) to be able to pass in what ever args I need to. d ___ 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] |:::| can you write dynamic meathods in a class?
Hey Guys, check this out Var clickHandler:Function = MyClass.staticMethod; var args:Array = ['Can', 'pass', 'in', 'any', 'amount']; newBtn.addEventListener("click", Delegate.create(this, function(evt:Object, meth:Function, args:Array) { meth.apply(null, args) }, clickHandler, args ) ); Regards, Bjorn Schultheiss Senior Flash Developer QDC Technologies -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of dnk Sent: Monday, 14 August 2006 5:17 AM To: Flashcoders mailing list Subject: Re: [Flashcoders] |:::| can you write dynamic meathods in a class? Ramon Miguel M. Tayag wrote: > Sometimes some events pass their own args and you dont even see them.. > > Try changing your function to this: > > function onHit1(o:Object, n:Number) //the o object is passed by the > listener { >trace("it was hit with the number: " + n); } > That worked perfect!!! Thanks sooo much! d ___ 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] |:::| can you write dynamic meathods in a class?
Ramon Miguel M. Tayag wrote: Sometimes some events pass their own args and you dont even see them.. Try changing your function to this: function onHit1(o:Object, n:Number) //the o object is passed by the listener { trace("it was hit with the number: " + n); } That worked perfect!!! Thanks sooo much! d ___ 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] |:::| can you write dynamic meathods in a class?
Give us the code of the dispatching of the event ... dnk wrote: > Ramon Miguel M. Tayag wrote: >> http://board.flashkit.com/board/showthread.php?t=662329&highlight=delegate >> >> > How do you call this class? > > I tried > > > import com.includingatree.utils.Delegate; > //use the delegate > this.menuBtn.addEventListener("click", Delegate.create(this, onHit1, 1)); > //create the btn event to handle the click > function onHit1(n:Number) > { >trace("it was hit with the number: " + n); > } > > > But I get returned: > > it was hit with the number: [object Object] > > > What would I be doing wrong? > > > ___ > 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] |:::| can you write dynamic meathods in a class?
Why yes, that is possible too: dynamic class Foo { function Foo() { this["test"+5] = function() { trace("Hello World"); } } } //fla file var myFoo = new Foo(); myFoo.test5(); But I really wouldn't do it like that... I would rather store a reference to the scope of the class, inside the button and declare the function in it's own scope: function buildMenu() { for (var i:Number = 0; i < 10; i++) { this._targetMc.createObject("menuMc", "menuMc" + i, this._targetMc[this._currCat].getNextHighestDepth()); this_targetMc["menuMc"+i].menuBtn.lScope = this; this._targetMc["menuMc" + i].menuBtn.onPress = function() { trace("The button was hit!"); trace("A reference to the class: "+this.lScope); //this will trace [object Object], which is correct } } } dnk wrote: > On 8/11/06, Jeroen Beckers <[EMAIL PROTECTED]> wrote: >>> Just to be complete: Yes, it is possible! >>> >>> Example: >>> >>> var myFoo = new Foo(); >>> myFoo["test"+5] = function() >>> { >>> trace("hello world!"); >>> } >>> myFoo.test5(); >>> >>> >>> //Foo.as >>> dynamic class Foo >>> { >>> >>> >>> } >>> >>> And to your second question: >>> >>> Delegate returns a function. Setting the onRelease to >>> 'Delegate.create()' is nothing more than setting the onRelease to an >>> ordinary function like this: >>> btn.onRelease = function() >>> { >>> trace("Hello World"); >>> } >>> >>> the only thing Delegate do, is modifie the scope of the function. >>> So, yes, you CAN overwrite 'delegate instances'. >>> >>> Ps: "Delegate instances" isn't even the right term since you don't >>> create an instance of the Delegate class. The 'create' method is a >>> static method that just takes some arguments and returns a function. >>> >>> Got it ? :) > Thanks for the pointers! > > One thing I need to clarify... > > I want to write the methods INSIDE the class. Would that work? > > For example: > > class TheMenu { > > function TheMenu() { > > } > function buildMenu() { > > for (var i:Number = 0; i < 10; i++) { > > this._targetMc.createObject("menuMc", "menuMc" + i, > this._targetMc[this._currCat].getNextHighestDepth()); > > this._targetMc["menuMc" + i].menuBtn.onPress = Delegate.create(this, > ["onHit" + i]); > > function ["onHit" + i]() { >trace("the button hit was hit"); > } > > } > > } > > } > > > > > ___ > 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] |:::| can you write dynamic meathods in a class?
Sometimes some events pass their own args and you dont even see them.. Try changing your function to this: function onHit1(o:Object, n:Number) //the o object is passed by the listener { trace("it was hit with the number: " + n); } On 8/13/06, dnk <[EMAIL PROTECTED]> wrote: Ramon Miguel M. Tayag wrote: > http://board.flashkit.com/board/showthread.php?t=662329&highlight=delegate > > How do you call this class? I tried import com.includingatree.utils.Delegate; //use the delegate this.menuBtn.addEventListener("click", Delegate.create(this, onHit1, 1)); //create the btn event to handle the click function onHit1(n:Number) { trace("it was hit with the number: " + n); } But I get returned: it was hit with the number: [object Object] What would I be doing wrong? ___ 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 -- Ramon Miguel M. Tayag ___ 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] |:::| can you write dynamic meathods in a class?
Ramon Miguel M. Tayag wrote: http://board.flashkit.com/board/showthread.php?t=662329&highlight=delegate How do you call this class? I tried import com.includingatree.utils.Delegate; //use the delegate this.menuBtn.addEventListener("click", Delegate.create(this, onHit1, 1)); //create the btn event to handle the click function onHit1(n:Number) { trace("it was hit with the number: " + n); } But I get returned: it was hit with the number: [object Object] What would I be doing wrong? ___ 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] |:::| can you write dynamic meathods in a class?
On 8/11/06, Jeroen Beckers <[EMAIL PROTECTED]> wrote: Just to be complete: Yes, it is possible! Example: var myFoo = new Foo(); myFoo["test"+5] = function() { trace("hello world!"); } myFoo.test5(); //Foo.as dynamic class Foo { } And to your second question: Delegate returns a function. Setting the onRelease to 'Delegate.create()' is nothing more than setting the onRelease to an ordinary function like this: btn.onRelease = function() { trace("Hello World"); } the only thing Delegate do, is modifie the scope of the function. So, yes, you CAN overwrite 'delegate instances'. Ps: "Delegate instances" isn't even the right term since you don't create an instance of the Delegate class. The 'create' method is a static method that just takes some arguments and returns a function. Got it ? :) Thanks for the pointers! One thing I need to clarify... I want to write the methods INSIDE the class. Would that work? For example: class TheMenu { function TheMenu() { } function buildMenu() { for (var i:Number = 0; i < 10; i++) { this._targetMc.createObject("menuMc", "menuMc" + i, this._targetMc[this._currCat].getNextHighestDepth()); this._targetMc["menuMc" + i].menuBtn.onPress = Delegate.create(this, ["onHit" + i]); function ["onHit" + i]() { trace("the button hit was hit"); } } } } ___ 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] |:::| can you write dynamic meathods in a class?
Also, look into __resolve. The Flash docs have excellent examples. Jim Kremens On 8/11/06, Jeroen Beckers <[EMAIL PROTECTED]> wrote: Just to be complete: Yes, it is possible! Example: var myFoo = new Foo(); myFoo["test"+5] = function() { trace("hello world!"); } myFoo.test5(); //Foo.as dynamic class Foo { } And to your second question: Delegate returns a function. Setting the onRelease to 'Delegate.create()' is nothing more than setting the onRelease to an ordinary function like this: btn.onRelease = function() { trace("Hello World"); } the only thing Delegate do, is modifie the scope of the function. So, yes, you CAN overwrite 'delegate instances'. Ps: "Delegate instances" isn't even the right term since you don't create an instance of the Delegate class. The 'create' method is a static method that just takes some arguments and returns a function. Got it ? :) Bbt Lists wrote: > Hi there > > Can you write dynamic methods in a class? > > > for example > > for (var i:Number = 0; i < 11; i++) > { >function onBtnPress + i() >{ > trace("Button number: " + i + "was pressed"); >} > } > > So then that would essentially create 10 methods (onBtnPress0 to > onBtnPress9) to be used by various onPress events. > > Is this possible? Then at the same time you could write the delegate > and create the buttons and so one as well. > > Then continuing on my thought - could you then over-write the > onBtnPress functions with new values (say for example the trace would be: > > trace("Button number: " + i + "was pressed with the currValue of " + > externalVariable); > > instead of the original: > > trace("Button number: " + i + "was pressed"); > > > I am a hobby AS coder, and I am probably way off here. All I am trying > to do is build a thumbnail nav for a gallery. > > Thanks in advance! > ___ 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 -- Jim Kremens ___ 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] |:::| can you write dynamic meathods in a class?
Just to be complete: Yes, it is possible! Example: var myFoo = new Foo(); myFoo["test"+5] = function() { trace("hello world!"); } myFoo.test5(); //Foo.as dynamic class Foo { } And to your second question: Delegate returns a function. Setting the onRelease to 'Delegate.create()' is nothing more than setting the onRelease to an ordinary function like this: btn.onRelease = function() { trace("Hello World"); } the only thing Delegate do, is modifie the scope of the function. So, yes, you CAN overwrite 'delegate instances'. Ps: "Delegate instances" isn't even the right term since you don't create an instance of the Delegate class. The 'create' method is a static method that just takes some arguments and returns a function. Got it ? :) Bbt Lists wrote: > Hi there > > Can you write dynamic methods in a class? > > > for example > > for (var i:Number = 0; i < 11; i++) > { >function onBtnPress + i() >{ > trace("Button number: " + i + "was pressed"); >} > } > > So then that would essentially create 10 methods (onBtnPress0 to > onBtnPress9) to be used by various onPress events. > > Is this possible? Then at the same time you could write the delegate > and create the buttons and so one as well. > > Then continuing on my thought - could you then over-write the > onBtnPress functions with new values (say for example the trace would be: > > trace("Button number: " + i + "was pressed with the currValue of " + > externalVariable); > > instead of the original: > > trace("Button number: " + i + "was pressed"); > > > I am a hobby AS coder, and I am probably way off here. All I am trying > to do is build a thumbnail nav for a gallery. > > Thanks in advance! > ___ 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: Re: [Flashcoders] |:::| can you write dynamic meathods in a class?
com.dynamicflash.utils.Delegate is the other Delegate class that allows argument passing. http://dynamicflash.com/2005/02/delegate-class-refined/ -mark > > From: Bbt Lists <[EMAIL PROTECTED]> > Date: 2006/08/11 Fri PM 12:54:04 CDT > To: Flashcoders mailing list > Subject: Re: [Flashcoders] |:::| can you write dynamic meathods in a class? > > Ramon Miguel M. Tayag wrote: > > Sorry, I'm using a custom delegate class.. I completely forgot. Let > > me dig up that post that has what you need... > > > I was just reading a reference to a "proxy" class that does similar to > delegate, but allows args to the functions. So I was not entirely insane > (as in not knowing about passing args with delegate). > > Curious to see if you are referencing the same class. > > And also I still have my question about re-assigning a new arg. > > -- > dnk > > ___ > 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 > -- John Mark Hawley The Nilbog Group 773.968.4980 (cell) ___ 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] |:::| can you write dynamic meathods in a class?
Ramon Miguel M. Tayag wrote: Sorry, I'm using a custom delegate class.. I completely forgot. Let me dig up that post that has what you need... I was just reading a reference to a "proxy" class that does similar to delegate, but allows args to the functions. So I was not entirely insane (as in not knowing about passing args with delegate). Curious to see if you are referencing the same class. And also I still have my question about re-assigning a new arg. -- dnk ___ 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] |:::| can you write dynamic meathods in a class?
http://board.flashkit.com/board/showthread.php?t=662329&highlight=delegate On 8/12/06, Ramon Miguel M. Tayag <[EMAIL PROTECTED]> wrote: Sorry, I'm using a custom delegate class.. I completely forgot. Let me dig up that post that has what you need... -- Ramon Miguel M. Tayag ___ 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] |:::| can you write dynamic meathods in a class?
Sorry, I'm using a custom delegate class.. I completely forgot. Let me dig up that post that has what you need... On 8/12/06, Bbt Lists <[EMAIL PROTECTED]> wrote: Ramon Miguel M. Tayag wrote: > I don't think you can create dynamic functions.. even if you could, I > don't see the need to. > > use your arguments to make your functions all-purpose. > > Ex. > > function onBtnPress(n:Number):Void > { > trace(n + " was pressed."); > } > > button0.onRelease = Delegate.create(this, onBtnPress, 0); > button1.onRelease = Delegate.create(this, onBtnPress, 1); > > Ah! I never knew you could throw args like that to your functions through delegate Sweet! That totally makes more sense! Now my next question Say for example I needed to throw a different arg to that function? IE this time I needed one var, and later I needed another? var nMyNum:Number = 0; button0.onRelease = Delegate.create(this, onBtnPress, nMyNum); nMyNum = 10; //need to update the delegate here //button0.onRelease = Delegate.create(this, onBtnPress, nMyNum); Can you remove or overwrite delegate instances? -- dnk ___ 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 -- Ramon Miguel M. Tayag ___ 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] |:::| can you write dynamic meathods in a class?
Ramon Miguel M. Tayag wrote: I don't think you can create dynamic functions.. even if you could, I don't see the need to. use your arguments to make your functions all-purpose. Ex. function onBtnPress(n:Number):Void { trace(n + " was pressed."); } button0.onRelease = Delegate.create(this, onBtnPress, 0); button1.onRelease = Delegate.create(this, onBtnPress, 1); Ah! I never knew you could throw args like that to your functions through delegate Sweet! That totally makes more sense! Now my next question Say for example I needed to throw a different arg to that function? IE this time I needed one var, and later I needed another? var nMyNum:Number = 0; button0.onRelease = Delegate.create(this, onBtnPress, nMyNum); nMyNum = 10; //need to update the delegate here //button0.onRelease = Delegate.create(this, onBtnPress, nMyNum); Can you remove or overwrite delegate instances? -- dnk ___ 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] |:::| can you write dynamic meathods in a class?
I don't think you can create dynamic functions.. even if you could, I don't see the need to. use your arguments to make your functions all-purpose. Ex. function onBtnPress(n:Number):Void { trace(n + " was pressed."); } button0.onRelease = Delegate.create(this, onBtnPress, 0); button1.onRelease = Delegate.create(this, onBtnPress, 1); On 8/12/06, Bbt Lists <[EMAIL PROTECTED]> wrote: Hi there Can you write dynamic methods in a class? for example for (var i:Number = 0; i < 11; i++) { function onBtnPress + i() { trace("Button number: " + i + "was pressed"); } } So then that would essentially create 10 methods (onBtnPress0 to onBtnPress9) to be used by various onPress events. Is this possible? Then at the same time you could write the delegate and create the buttons and so one as well. Then continuing on my thought - could you then over-write the onBtnPress functions with new values (say for example the trace would be: trace("Button number: " + i + "was pressed with the currValue of " + externalVariable); instead of the original: trace("Button number: " + i + "was pressed"); I am a hobby AS coder, and I am probably way off here. All I am trying to do is build a thumbnail nav for a gallery. Thanks in advance! -- dnk -- Ramon Miguel M. Tayag ___ 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