Re: [Flashcoders] Regarding ascb Proxy

2006-06-09 Thread mike cann

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


Re: [Flashcoders] Regarding ascb Proxy

2006-06-09 Thread erixtekila

Hi,



I have slightly modify the Joey's version.
I use also the Array.slice which is faster than the loop.

For the last arguments, it's a mean to get a reference added as a end 
param to the callback handler.

Easier to dereference after.

Note the return at the end of the functions.
French comments for inside for more insights.

//!-- UTF8
/*
-
Proxy

package : com.person13.ascb.util
Description :
Sert d'intermédiaire pour la délégation de référence de 
fonction.
Cas d'un callback avec nécessité de portée spécifiqye.
-
   ##++
   ##Copyright (c) 2005
   ##http://www.v-i-a.net
   ##All Rights Reserved
   ##
   ##E-Mail: [EMAIL PROTECTED]
   ##
   ##Permission to use, copy, modify and distribute is hereby 
granted,

   ##providing that no charges are involved and the above  copyright
   ##notice and this permission appear in all copies and in 
supporting
   ##documentation. Requests for other distribution rights, 
including
   ##incorporation in commercial  products,  such as  books,  
magazine

   ##articles, or CD-ROMS should be made to the authors.
   ##
   ##This  program  is distributed in the hope that it will be 
useful,
   ##but WITHOUT ANY WARRANTY;  without  even  the implied warranty 
of

   ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   ##--

   For complete Licence of the Creative Commons
   Attribution-NonCommercial-ShareAlike 2.0
   See : http://creativecommons.org/licenses/by-nc-sa/2.0/
-
version history :
1.0 : 17 juin 2005
- Reprise du code de Joey Lott
1.1 : 04 juillet 2005
- Rajout d'un retour pour les fonctions 
procurées.
- Rajout d'un nouvel argument pour 
déréférencer le proxy
par la suite.
-

/**
 *  Utile pour créer une référence de callback.
 *  - pour un observateur sur une fonction (listener function)
 *  - pour un callback d'un classe composant une autre classe
 *
 *	La fonction callback recevra une référence à la fonction Proxy en 
dernier paramètre.
 *	Il est ainsi possible d'utiliser EventSource.removeEventListener 
(EventName, ProxyRef)

 *  et de supprimer la référenec au proxy.
 *
 *  @author Joey Lott http://www.person13.com
 *  @author erixtekila copyleft http://www.v-i-a.net
 *  @version 1.1
 */
class com.person13.ascb.util.Proxy
{
/**
 *  Méthode factory pour appliquer une référence à un callback
	 *	Note : Le dernier paramètre envoyé à la méthode proxiée et une 
référence au proxy.

 *  Ainsi, depuis celle-ci il est possible de le déréférencer.
 *  cf http://dynamicflash.com/2005/02/delegate-class-refined
 *  
 *  @param oTarget  Objet cible du callback.
 *  @param fFunctionCallback.
 *  @return Une référence à la fonction Proxy
 */
	public static function create (oTarget:Object, 
fFunction:Function):Function

{
/* Modifié de l'original
var aParameters:Array = new Array();
for(var i:Number = 2; i  arguments.length; i++) {
aParameters[i - 2] = arguments[i];
}*/
// Paramètres à passer au callback
var aParameters:Array;
aParameters = arguments.splice (2);

// EventProxy, référence à une fonction
var fProxy:Function = function ():Object
{
// Paramètres
var aActualParameters:Array = arguments.concat 
(aParameters);
// Rajout de la référence au Proxy à la fin des 
paramètres
/**
 * Permet de déréférencer la proxy depuis la fonction 
soumise
			 * Exemple : cf 
http://dynamicflash.com/2005/02/delegate-class-refined

 *
 *  public function 
DFDelegateTest(textArea:TextArea) {
 *  _textArea = textArea;
			 *		_textArea.addEventListener(change, Delegate.create(this, 
onTextAreaChange));

 *  }
 *
			 *	private function onTextAreaChange(event:Object, 
delegate:Function) : Void {

 *  _textArea.removeEventListener(change, 
delegate);
 *  }
 */
aActualParameters.push (arguments.callee);

Re: [Flashcoders] Regarding ascb Proxy

2006-06-09 Thread js
Thank you for this excellent enhanced version erixtekila. Just read 
through the blog post on http://dynamicflash.com/ and it was also a 
good read. He actually updated the class if you didn't notice--you can 
find it here: http://dynamicflash.com/classes/Delegate.as



erixtekila wrote:

Hi,



I have slightly modify the Joey's version.
I use also the Array.slice which is faster than the loop.

For the last arguments, it's a mean to get a reference added as a end 
param to the callback handler.

Easier to dereference after.

Note the return at the end of the functions.
French comments for inside for more insights.

//!-- UTF8
/*
-
Proxy

package : com.person13.ascb.util

Description :
Sert d'intermédiaire pour la délégation de référence de fonction.
Cas d'un callback avec nécessité de portée spécifiqye.
-
   ##++
   ##Copyright (c) 2005
   ##http://www.v-i-a.net
   ##All Rights Reserved
   ##
   ##E-Mail: [EMAIL PROTECTED]
   ##
   ##Permission to use, copy, modify and distribute is hereby granted,
   ##providing that no charges are involved and the above  copyright
   ##notice and this permission appear in all copies and in supporting
   ##documentation. Requests for other distribution rights, including
   ##incorporation in commercial  products,  such as  books,  magazine
   ##articles, or CD-ROMS should be made to the authors.
   ##
   ##This  program  is distributed in the hope that it will be useful,
   ##but WITHOUT ANY WARRANTY;  without  even  the implied warranty of
   ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   ##--

   For complete Licence of the Creative Commons
   Attribution-NonCommercial-ShareAlike 2.0
   See : http://creativecommons.org/licenses/by-nc-sa/2.0/
-
version history :
1.0 : 17 juin 2005
- Reprise du code de Joey Lott
1.1 : 04 juillet 2005
- Rajout d'un retour pour les fonctions procurées.
- Rajout d'un nouvel argument pour déréférencer le 
proxy

par la suite.
-

/**
 *Utile pour créer une référence de callback.
 *- pour un observateur sur une fonction (listener function)
 *- pour un callback d'un classe composant une autre classe
 *
 *La fonction callback recevra une référence à la fonction Proxy en 
dernier paramètre.
 *Il est ainsi possible d'utiliser EventSource.removeEventListener 
(EventName, ProxyRef)

 *et de supprimer la référenec au proxy.
 *
 *@authorJoey Lott http://www.person13.com
 *@author erixtekila copyleft http://www.v-i-a.net
 *@version 1.1
 */
class com.person13.ascb.util.Proxy
{
/**
 *Méthode factory pour appliquer une référence à un callback
 *Note : Le dernier paramètre envoyé à la méthode proxiée et une 
référence au proxy.

 *Ainsi, depuis celle-ci il est possible de le déréférencer.
 *cf http://dynamicflash.com/2005/02/delegate-class-refined
 *   
 *@param oTargetObjet cible du callback.

 *@param fFunctionCallback.
 *@return Une référence à la fonction Proxy
 */
public static function create (oTarget:Object, 
fFunction:Function):Function

{
/* Modifié de l'original
var aParameters:Array = new Array();
for(var i:Number = 2; i  arguments.length; i++) {
aParameters[i - 2] = arguments[i];
}*/
// Paramètres à passer au callback
var aParameters:Array;
aParameters = arguments.splice (2);
   
// EventProxy, référence à une fonction

var fProxy:Function = function ():Object
{
// Paramètres
var aActualParameters:Array = arguments.concat (aParameters);
// Rajout de la référence au Proxy à la fin des paramètres
/**
 * Permet de déréférencer la proxy depuis la fonction soumise
 * Exemple : cf 
http://dynamicflash.com/2005/02/delegate-class-refined

 *
 * public function DFDelegateTest(textArea:TextArea) {
 * _textArea = textArea;
 *_textArea.addEventListener(change, 
Delegate.create(this, onTextAreaChange));

 *}
 *
 *private function onTextAreaChange(event:Object, 
delegate:Function) : Void {

 *_textArea.removeEventListener(change, delegate);
 *}
 */
aActualParameters.push (arguments.callee);
// Activation
// Rajout d'un return pour correspondre au fonctionnement de 
mx.util.Delegate.

return fFunction.apply (oTarget,