all groups > flash actionscript > april 2004 >
You're in the

flash actionscript

group:

Function execution order


Function execution order Laiverd.COM
4/1/2004 11:02:21 PM
flash actionscript:
Been playing around with calling a function from another function through a
parameter. This is what I have:

// code
callFunction = function (c, d, e, func) {
trace(c + " " + d + " " + e);
func;

};
paramFunction = function (a, b, c) {
trace(a);
trace(b);
trace(c);
};
callFunction("this", "will", "call", paramFunction("this", "is", "param"));

The output of all the tracing is:

this
is
param
this will call

It seems that the func parameter is run before the trace in callFunction().
Why? Do function calls somehow take precedence over something like a trace
(which basically also is a function)?? Some light please ?!

John


--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

Re: Function execution order Butt Sparkler
4/2/2004 8:23:31 AM
John,

In your example you aren't passing a function as the last parameter you are
making a function call, so the value of "func" inside of callFunction is
acutally "undefined" since paramFunction doesn't return anything. the 2nd line
of callFunction doesn't do anything btw.

Hope that clears things up a bit.
Re: Function execution order Peter Blumenthal
4/2/2004 9:04:23 AM
heh - that's interesting John!

Check this out. If you replace your callFunction() with this:

callFunction = function (c, d, e, func) {
trace(c+" "+d+" "+e);
};


You get exactly the same result. It would appear that the function is being
called by the 'func' parameter as it is [set/passed into] the function? If
you put a break point on your line:

callFunction("this", "will", "call", paramFunction("this", "is", "param"));

and step through the code you can kinda see it happen.

}`¬P

--
---------------------------------------
http://www.phageinteractive.com
PhageInteractive Ltd.
remove mm_ to mail
---------------------------------------
'If I come across as a grumpy and twisted old man, it's just because I'm a
grumpy, twisted, old man." - me
---------------------------------------

Re: Function execution order Peter Blumenthal
4/2/2004 10:07:14 AM

well, this works:

callFunction = function (c, d, e, func) {
trace(c+" "+d+" "+e);
func(c,d,e);
};
paramFunction = function (a, b, c) {
trace(a);
trace(b);
trace(c);
};
callFunction("this", "will", "call", paramFunction);


}`¬P
--
---------------------------------------
http://www.phageinteractive.com
PhageInteractive Ltd.
remove mm_ to mail
---------------------------------------
'If I come across as a grumpy and twisted old man, it's just because I'm a
grumpy, twisted, old man." - me
---------------------------------------

Re: Function execution order Laiverd.COM
4/2/2004 10:40:36 AM
Thanks for the input guys. I'm beginning to develop the beginning of
understanding here ;-) From Flashcoders I learned this in the meantime:

Thanks to Liam Egan:
By placing the function call like that you're actually executing it. The way
to pass a function as an argument is by doing it this way;

// code

callFunction = function (c, d, e, func) {

trace(c + " " + d + " " + e);

func();

};

paramFunction = function (a, b, c) {

trace(a);

trace(b);

trace(c);

};

callFunction("this", "will", "call", paramFunction);



This will trace things in the order expected. Question that does remain is
how to use parameters in the function that is is used as a parameter itself.



John


--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

Re: Function execution order Laiverd.COM
4/2/2004 11:38:35 AM
Yep, but how about passing parameters from paramFunction ;-)

John

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

Re: Function execution order Laiverd.COM
4/2/2004 11:40:04 AM
I am currently having a look at Function.call() and Function.apply() but
having a hard time coming to terms with it. If anyone understands these
methods and would be willing to provide an example with the code in my
original post, I would appreciate it.

John

--
----------------------------------------------------------------------------
-----------
RESOURCES
http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash
----------------------------------------------------------------------------
-----------
TUTORIALS at
www.laiverd.com
Flash & PHP Emailform
Using textfiles in Flash
----------------------------------------------------------------------------
-----------

AddThis Social Bookmark Button