Thank you Mike for your post, however, regarding your second point I wasn't referring to the ability to pass extra parameters to the proxy function. My specific confusion surrounds the reasoning behind adding (via concat) the arguments of fProxy with the arguments of aParameters. Also notice that fProxy is a temporary, local function declared within Proxy.create so "arguments" in the following statement:

var aActualParameters:Array = arguments.concat(aParameters);

actually refer to the arguments of that local function, not the arguments of the parent class function, create().

Again, I am still confused as to why this step is necessary. Why could you not just do this:

fFunction.apply(oTarget, aParameters);

(I've tried it, and it works)

Any clarification would be greatly appreciated!


mike cann wrote:
Okay, i havent ever looked at the proxy class but i think i can take a stab
at answering some of your questions, others can probably back me up /
correct me on any errors.

1. Yes it appears he could have used slice, perhaps using the for loop is
quicker?

2. There are occasions when you want to pass the returning functions extra
parameters. When using the Macromedia Delegate class i came accross times
when it would have been neater to supply additional paramters, but it wasnt
essential. Im sure somone else can give you a specific example of when its
needed.

Mike

On 09/06/06, js <[EMAIL PROTECTED]> wrote:

I was taking a look recently at the Proxy class created by Joey Lott of
Person13 for educational purposes, as I have just started learning OOP,
and a couple questions popped into my mind.

Here is the full class:

class ascb.util.Proxy {

  public static function create(oTarget:Object,
fFunction:Function):Function {

    var aParameters:Array = new Array();

    for(var i:Number = 2; i < arguments.length; i++) {
      aParameters[i - 2] = arguments[i];
    }

    var fProxy:Function = function():Void {

      var aActualParameters:Array = arguments.concat(aParameters);
      fFunction.apply(oTarget, aActualParameters);

    };

    return fProxy;

  }

}

First of all, when populating aParameters, why couldn't you just do:

aParameters = arguments.slice(2);

That seems a lot more clean and improves readability a bit, no?

Second, why exactly do you need to concat the arguments of fProxy and
aParameters? I can see what it's doing; it's tacking on the additional
arguments supplied to Proxy.create onto the arguments of the fProxy
function (which is then returned) -- but I can't really envision a
situation where that would be needed? For instance:

class someClass {

    private var _someMc:MovieClip;

    function someClass(mc:MovieClip){

        _someMc = mc;

        _someMc.onRelease = Proxy.create(this,someMethod,1,2,3);

    }

    private function someMethod(a,b,c){

           trace(a+" "+b+" "+c);

    }

}

In what case would I be calling someMethod() via Proxy and supplying a
set of arguments that do not match the syntax of someMethod()? It seems
to me that you could just replace the following:

var aActualParameters:Array = arguments.concat(aParameters);
fFunction.apply(oTarget, aActualParameters);

with:

fFunction.apply(oTarget, aParameters);

Any clarification or insight is greatly appreciated.

Joseph Sorensen
aerosdesign.com/jsorensen
jsorensen[at]aerosdesign.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



--
--

*Joseph Sorensen* / *Skyform* ©
Web Design / Audio Production / Photography
*Web:* aerosdesign.com/jsorensen
*Em:* jsorensen[at]aerosdesign.com
*Ph:* 815.276.9006
_______________________________________________
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