Function question

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


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 :blush:

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

}
};

Thanks, i’ve added that.

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


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

Thanks :stuck_out_tongue: