# Problem returning values from a function

**URL:** <https://forum.kirupa.com/t/problem-returning-values-from-a-function/165671>\
**Category:** Uncategorized\
**Created:** [October 13, 2005, 1:26am UTC](https://forum.kirupa.com/t/problem-returning-values-from-a-function/165671 "2005-10-13T01:26:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![medicated](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@medicated](https://forum.kirupa.com/u/medicated)\
**Post date:** [October 13, 2005, 1:26am UTC](https://forum.kirupa.com/t/problem-returning-values-from-a-function/165671/1 "2005-10-13T01:26:23Z")

</div>

I need to load data from a database, so I created the following function and placed it in frame 2 on the main timeline.

```auto

getQuestionSet = function (category:String, subject:String, level:Number, count:Number):Array {
	var questionSet:Array = new Array();
	var writeV:LoadVars = new LoadVars();
	var readV:LoadVars = new LoadVars();
	// stop browser from returning cached results
	writeV.cacheKiller = new Date().getTime();
	writeV.category = category;
	writeV.subject = subject;
	writeV.level = level;
	writeV.count = count;
	trace(writeV.toString());
	writeV.sendAndLoad("getQuestionSet.aspx", readV, "GET");
	readV.onLoad = function(success) {
		if (success) {
			questionSet[0] = readV.pk1;
			questionSet[1] = readV.pk2;
			questionSet[2] = readV.pk3;
			questionSet[3] = readV.pk4;
			questionSet[4] = readV.pk5;
			questionSet[5] = readV.pk6;
			questionSet[6] = readV.pk7;
			questionSet[7] = readV.pk8;
			questionSet[8] = readV.pk9;
			questionSet[9] = readV.pk10;
			_root.questions = questionSet;
		}
	};
	return questionSet;
};

```

I also created a variable in the first frame of the main timeline as so.

```auto

var questions:Array = new Array();

```

Whenever I try to call the function, it fails to set the value of the questions array. It always appears empty(questions[0]-questions[10] have the value undefined). But, if I check the values from within the function after I have set them, it works, so I know that it is receiving the values. What am I doing wrong?

```auto

questions = getQuestionSet("Art and Music", "Art", 1, 10);

```

Here is an example of how I have would call the function.  
Also, please feel free to give me constructive comments on my actionscripting, I’m still new.
