|
List Info
Thread: trying to call a function passed as an argument
|
|
| trying to call a function passed as an
argument |

|
2006-06-29 19:21:47 |
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/flashcode
rs
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
|
|
| trying to call a function passed as an
argument |

|
2006-06-29 20:41:37 |
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: flashcoders-bounces chattyfig.figleaf.com
[mailto:flashcoders-bounces chattyfig.figleaf.com] 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/flashcode
rs
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training http://www.figleaf.com
http://training.figleaf.c
om
_______________________________________________
Flashcoders chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
|
|
| trying to call a function passed as an
argument |

|
2006-06-29 20:46:28 |
damn, should be:
o[ method ].apply( o, ... args... );
Long day...
~neo
-----Original Message-----
From: flashcoders-bounces chattyfig.figleaf.com
[mailto:flashcoders-bounces chattyfig.figleaf.com] 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: flashcoders-bounces chattyfig.figleaf.com
[mailto:flashcoders-bounces chattyfig.figleaf.com] 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/flashcode
rs
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training http://www.figleaf.com
http://training.figleaf.c
om
_______________________________________________
Flashcoders chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training http://www.figleaf.com
http://training.figleaf.c
om
_______________________________________________
Flashcoders chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
|
|
| trying to call a function passed as an
argument |

|
2006-06-29 20:06:25 |
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: flashcoders-bounces chattyfig.figleaf.com
[mailto:flashcoders-
> bounces chattyfig.figleaf.com] 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/flashcode
rs
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.c
om
_______________________________________________
Flashcoders chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om
|
|
[1-4]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|