# Stack Overflow / recursion

**URL:** <https://forum.kirupa.com/t/stack-overflow-recursion/315846>\
**Category:** flash\
**Created:** [November 5, 2010, 4:03pm UTC](https://forum.kirupa.com/t/stack-overflow-recursion/315846 "2010-11-05T16:03:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![laira1](https://avatars.discourse-cdn.com/v4/letter/l/b38774/32.png) [@laira1](https://forum.kirupa.com/u/laira1)\
**Post date:** [November 5, 2010, 4:03pm UTC](https://forum.kirupa.com/t/stack-overflow-recursion/315846/1 "2010-11-05T16:03:13Z")

</div>

I’ve been following a tutorial that gave me the following two functions for a randomized question from an XML list:

```auto

var questions:Array=new Array();
var answers:Array=new Array();
var totalAmountWon:Number = 0;
var amountWonThisRound:Number;

var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("sample.xml"));
loader.addEventListener(Event.COMPLETE, loadXML);

function loadXML(e:Event):void
{
        var myxml = new XML(e.target.data);
		var loop =myxml.ques.length();
		for (var i=0;i<loop;i++){questions*=myxml.ques*.q1;
		answers*=[myxml.ques*.op1,myxml.ques*.op2,myxml.ques*.op3];
 
		}
		gotoAndPlay(2);
		}

function change_question()
{
		
	if (questionnumber == numberOfQuestions)
	{
		gotoAndPlay(5);
	}
	else
	{
		rnd1 = Math.ceil(Math.random() * 3);
		rnd2 = Math.ceil(Math.random() * questions.length) - 1;
		q.text = questions[rnd2];

		if (questions[rnd2] == "x")
		{
			change_question();
		}
		questions[rnd2] = "x";

		if (rnd1 == 1)
		{
			shade1.opt1.text = answers[rnd2][0];
			shade2.opt2.text = answers[rnd2][1];
			shade3.opt3.text = answers[rnd2][2];
		}
		if (rnd1 == 2)
		{
			shade1.opt1.text = answers[rnd2][2];
			shade2.opt2.text = answers[rnd2][0];
			shade3.opt3.text = answers[rnd2][1];
		}
		if (rnd1 == 3)
		{
			shade1.opt1.text = answers[rnd2][1];
			shade2.opt2.text = answers[rnd2][2];
			shade3.opt3.text = answers[rnd2][0];
		}
	}
}

```

Eventually, I started hitting a stack overflow around the q.text line, and even though I’m a total n00b, I noticed that the function is calling itself, which I’m told is bad code. Because I’m a total n00b, however, I don’t know how to correct it. Any advice?
