Re: [Flashcoders] trying to call a function passed as an argument

2006-06-30 Thread Latcho

if the function-param in

 public function doFirst(aString:String, bString:String,
aFunction:Function)

is a good reference to an existing function

you don't need to use the call()

to execute aFunction you can just use 


public function doFirst(aString:String, bString:String,aFunction:Function) {
	var newParam:String=pass it on!   
	 aFunction(newParam)

}

If that is what you wanted to know...


If the aFunction would be a String you should indeed use call()
_root[func].call();

-Latcho-






John Mark Hawley wrote:

You can't pass a reference to a method call like you seem to be trying to do by 
'bar.doLast'. You *can* pass functions around, but not object methods -- they 
no longer know what object they are supposed to act on.

See:

var a:Array = [1, 2, 3];
a.shift(); // a = [2, 3];
var shiftMethod:Function = a.shift;
shiftMethod(); // a still equals [2, 3] - this did nothing

One solution would be something like this:

public function doFirst(aString:String, aBarInstance:Bar, 
aBarMethodName:String) {
 trace(the first string is +aString);
 
 aBar[aBarMethodName]();

}

This is pretty nasty, though. You should probably let us know what the effect 
you are going for is so someone can suggest a better way, probably involving 
either untangling these two objects or using mx.utils.Delegate.

-mark hawley
  

From: Elie Zananiri [EMAIL PROTECTED]
Date: 2006/06/29 Thu PM 02:21:47 CDT
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] trying to call a function passed as an argument

Hi all,

I have this method where I need to call a function passed as an argument
(kind of like in setInterval()) and I don't understand the documentation and
can't get it to work.

First of all, I don't understand how to pass the function as a parameter.
Am I passing a String or an actual Function object?  Can I pass a Function
with parameters?  Do I have to write the parentheses in the parameter?

Next, how do I call this function?  The Function.call() function requires a
parameter but I don't get what it does...

Thanks for the help!

-Elie

Here is the structure I have:

class Bar {
  public Bar() {
  }

  public function doLast(bString:String) {
trace(the second string is +bString);
  }
}

class Foo {
  var bar:Bar;

  public Foo() {
bar = new Bar();
doFirst(hello, world, bar.doLast);
  }

  public function doFirst(aString:String, bString:String,
aFunction:Function) {
trace(the first string is +aString);

// call the second function here ???
aFunction.call(??);
  }
}
___
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

  


___
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] trying to call a function passed as an argument

2006-06-30 Thread Doug Coning
This is how I do it:


var functA:Function = function(){
trace(A);
}

var functB:Function = function(){
trace(B);
}

function performFunctions(funct:Function){
funct();
}

performFunctions(functA);

performFunctions(functB);


Doug Coning 
Senior Web Development Programmer
FORUM Solutions, LLC
 
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:flashcoders-
 [EMAIL PROTECTED] On Behalf Of Elie Zananiri
 Sent: Thursday, June 29, 2006 3:22 PM
 To: flashcoders@chattyfig.figleaf.com
 Subject: [Flashcoders] trying to call a function passed as an argument
 
 Hi all,
 
 I have this method where I need to call a function passed as an
argument
 (kind of like in setInterval()) and I don't understand the
documentation
 and
 can't get it to work.
 
 First of all, I don't understand how to pass the function as a
parameter.
 Am I passing a String or an actual Function object?  Can I pass a
Function
 with parameters?  Do I have to write the parentheses in the parameter?
 
 Next, how do I call this function?  The Function.call() function
requires
 a
 parameter but I don't get what it does...
 
 Thanks for the help!
 
 -Elie
 
 Here is the structure I have:
 
 class Bar {
   public Bar() {
   }
 
   public function doLast(bString:String) {
 trace(the second string is +bString);
   }
 }
 
 class Foo {
   var bar:Bar;
 
   public Foo() {
 bar = new Bar();
 doFirst(hello, world, bar.doLast);
   }
 
   public function doFirst(aString:String, bString:String,
 aFunction:Function) {
 trace(the first string is +aString);
 
 // call the second function here ???
 aFunction.call(??);
   }
 }
 ___
 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] trying to call a function passed as an argument

2006-06-29 Thread John Mark Hawley
You can't pass a reference to a method call like you seem to be trying to do by 
'bar.doLast'. You *can* pass functions around, but not object methods -- they 
no longer know what object they are supposed to act on.

See:

var a:Array = [1, 2, 3];
a.shift(); // a = [2, 3];
var shiftMethod:Function = a.shift;
shiftMethod(); // a still equals [2, 3] - this did nothing

One solution would be something like this:

public function doFirst(aString:String, aBarInstance:Bar, 
aBarMethodName:String) {
 trace(the first string is +aString);
 
 aBar[aBarMethodName]();
}

This is pretty nasty, though. You should probably let us know what the effect 
you are going for is so someone can suggest a better way, probably involving 
either untangling these two objects or using mx.utils.Delegate.

-mark hawley
 
 From: Elie Zananiri [EMAIL PROTECTED]
 Date: 2006/06/29 Thu PM 02:21:47 CDT
 To: flashcoders@chattyfig.figleaf.com
 Subject: [Flashcoders] trying to call a function passed as an argument
 
 Hi all,
 
 I have this method where I need to call a function passed as an argument
 (kind of like in setInterval()) and I don't understand the documentation and
 can't get it to work.
 
 First of all, I don't understand how to pass the function as a parameter.
 Am I passing a String or an actual Function object?  Can I pass a Function
 with parameters?  Do I have to write the parentheses in the parameter?
 
 Next, how do I call this function?  The Function.call() function requires a
 parameter but I don't get what it does...
 
 Thanks for the help!
 
 -Elie
 
 Here is the structure I have:
 
 class Bar {
   public Bar() {
   }
 
   public function doLast(bString:String) {
 trace(the second string is +bString);
   }
 }
 
 class Foo {
   var bar:Bar;
 
   public Foo() {
 bar = new Bar();
 doFirst(hello, world, bar.doLast);
   }
 
   public function doFirst(aString:String, bString:String,
 aFunction:Function) {
 trace(the first string is +aString);
 
 // call the second function here ???
 aFunction.call(??);
   }
 }
 ___
 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] trying to call a function passed as an argument

2006-06-29 Thread neo binedell
Try something like this:

...
doFirst( hello, world, bar, doLast );
...
 
public function doFirst( aS:String, bS:String, o:Object, m:String )
{
trace(the first string is +aString);

// call the second function here ???
   a[ method ].apply( a, ... args... );
}

~neo

ps:
Interestingly enough addEventListener in AS3 does 
what your code wants to do implicitly ;p

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Elie
Zananiri
Sent: 29 June 2006 09:22 PM
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] trying to call a function passed as an argument

Hi all,

I have this method where I need to call a function passed as an argument
(kind of like in setInterval()) and I don't understand the documentation and
can't get it to work.

First of all, I don't understand how to pass the function as a parameter.
Am I passing a String or an actual Function object?  Can I pass a Function
with parameters?  Do I have to write the parentheses in the parameter?

Next, how do I call this function?  The Function.call() function requires a
parameter but I don't get what it does...

Thanks for the help!

-Elie

Here is the structure I have:

class Bar {
  public Bar() {
  }

  public function doLast(bString:String) {
trace(the second string is +bString);
  }
}

class Foo {
  var bar:Bar;

  public Foo() {
bar = new Bar();
doFirst(hello, world, bar.doLast);
  }

  public function doFirst(aString:String, bString:String,
aFunction:Function) {
trace(the first string is +aString);

// call the second function here ???
aFunction.call(??);
  }
}
___
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] trying to call a function passed as an argument

2006-06-29 Thread neo binedell
damn, should be:

o[ method ].apply( o, ... args... );


Long day...

~neo


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of neo binedell
Sent: 29 June 2006 10:42 PM
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] trying to call a function passed as an argument

Try something like this:

...
doFirst( hello, world, bar, doLast ); ...
 
public function doFirst( aS:String, bS:String, o:Object, m:String ) {
trace(the first string is +aString);

// call the second function here ???
   a[ method ].apply( a, ... args... );
}

~neo

ps:
Interestingly enough addEventListener in AS3 does what your code wants to do
implicitly ;p

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Elie
Zananiri
Sent: 29 June 2006 09:22 PM
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] trying to call a function passed as an argument

Hi all,

I have this method where I need to call a function passed as an argument
(kind of like in setInterval()) and I don't understand the documentation and
can't get it to work.

First of all, I don't understand how to pass the function as a parameter.
Am I passing a String or an actual Function object?  Can I pass a Function
with parameters?  Do I have to write the parentheses in the parameter?

Next, how do I call this function?  The Function.call() function requires a
parameter but I don't get what it does...

Thanks for the help!

-Elie

Here is the structure I have:

class Bar {
  public Bar() {
  }

  public function doLast(bString:String) {
trace(the second string is +bString);
  }
}

class Foo {
  var bar:Bar;

  public Foo() {
bar = new Bar();
doFirst(hello, world, bar.doLast);
  }

  public function doFirst(aString:String, bString:String,
aFunction:Function) {
trace(the first string is +aString);

// call the second function here ???
aFunction.call(??);
  }
}
___
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