# How to assign a function with arguments into a variable?

**URL:** <https://forum.kirupa.com/t/how-to-assign-a-function-with-arguments-into-a-variable/303315>\
**Category:** flash\
**Created:** [January 18, 2010, 5:26pm UTC](https://forum.kirupa.com/t/how-to-assign-a-function-with-arguments-into-a-variable/303315 "2010-01-18T17:26:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zoink](https://avatars.discourse-cdn.com/v4/letter/z/9d8465/32.png) [@zoink](https://forum.kirupa.com/u/zoink)\
**Post date:** [January 18, 2010, 5:26pm UTC](https://forum.kirupa.com/t/how-to-assign-a-function-with-arguments-into-a-variable/303315/1 "2010-01-18T17:26:05Z")

</div>

Here’s my problem:

I need to assign this function:

var f2:Function = function(i:String){  
trace("this is " + i);  
}

into a separate variable… something like var testVar:Function = f2(“TestString”); This doesn’t work because f2(“TestString”) gets executed. Any way to make it work?

var testVar:Function = f2 will work if f2 is a function that takes no arguemnts… But how will i make it work for functions that take in arguements? I tried to search for the answer but to no avail \>\_\<

Thanks =)

Sorry… I found the answer… \>\_\< Please close this thread… ANyway, here’s the answer i found:

[COLOR=#000000][FONT=Times New Roman][LEFT][FONT=monospace][COLOR=#993300]function[/COLOR] addfunction[COLOR=#000000]([/COLOR]AFunc:[COLOR=#993300]Function[/COLOR], \_param:[COLOR=#993300]String[/COLOR][COLOR=#000000])[/COLOR]  
[COLOR=#000000]{[/COLOR]  
[COLOR=#993300]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]"Function addfunction : AFunc = “[/COLOR] + AFunc + [COLOR=#0000FF]”[COLOR=#000099]\*\* \*\*[/COLOR]\_param = "[/COLOR] + \_param[COLOR=#000000])[/COLOR];  
AFuncCOLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]

[COLOR=#993300]function[/COLOR] showmessageCOLOR=#000000[/COLOR]  
[COLOR=#000000]{[/COLOR]  
[COLOR=#993300]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000FF]"Function showmessage : msg = "[/COLOR] + msg[COLOR=#000000])[/COLOR];  
[COLOR=#993300]trace[/COLOR]COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR]

addfunction[COLOR=#000000]([/COLOR]showmessage, [COLOR=#0000FF]“hello”[/COLOR][COLOR=#000000])[/COLOR];[/FONT][/LEFT][/FONT][/COLOR]

from: [http://www.actionscript.org/forums/showthread.php3?t=125939](http://www.actionscript.org/forums/showthread.php3?t=125939)
