# Function question

**URL:** https://forum.kirupa.com/t/function-question/60715
**Category:** flash
**Created:** [August 11, 2004, 10:38pm UTC](https://forum.kirupa.com/t/function-question/60715 "2004-08-11T22:38:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Uli](https://avatars.discourse-cdn.com/v4/letter/u/ccd318/32.png) [@Uli](https://forum.kirupa.com/u/Uli)
#### Post date: [August 11, 2004, 10:38pm UTC](https://forum.kirupa.com/t/function-question/60715/1 "2004-08-11T22:38:26Z")

</div>

Hello,

I’m “playing” with the function function :sigh: but it’s not working… I was wondering if using functions that way is the proper way… cause it doesn’t work here hehe

```php

tocheck = function (id) {
	_root.myData = new LoadVars();
	_root.myData.myid = _global.somearray[id];
	_root.myData.sendAndLoad("script.php", _root.myData, "POST");
	if (parseInt(this.sending) == 1) {
		_root.myMC.gotoAndStop(2);
	}
};

_root.somebutton.onPress = function() {
	for (id=0; id<20; d++) {
		test = tocheck(id);
		trace(test);
//returns undefined
	}
};

```

TiA 😊

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 11, 2004, 10:46pm UTC](https://forum.kirupa.com/t/function-question/60715/2 "2004-08-11T22:46:26Z")

</div>

you have to return a variable at the end of the function  
tocheck = function (id) {  
\_root.myData = new LoadVars();  
\_root.myData.myid = \_global.somearray[id];  
\_root.myData.sendAndLoad(“script.php”, \_root.myData, “POST”);  
if (parseInt(this.sending) == 1) {  
\_root.myMC.gotoAndStop(2);  
**return \_root.myData;** //for example

}  
};

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 12, 2004, 12:13am UTC](https://forum.kirupa.com/t/function-question/60715/3 "2004-08-12T00:13:27Z")

</div>

Thanks, i’ve added that.

But is that the correct way to call the function ? It doesn’t seem to work here…

```php

_root.somebutton.onPress = function() { 
    for (id=0; id<20; d++) { 
        test = tocheck(id); 
        trace(test); 
//returns undefined 
    } 
}; 

```

Thanks 😛
