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

Reply via email to