Reputation: 911
I have a function in my class that returns an array. Thing is, I get a Stack Overflow error when using. The important functions are:
ScrollList/returnArmy
public function returnArmy ( army:int ):Array
{
var returnVar:Array;
if( army == 0 ) returnVar = army1_;
else if( army == 1 ) returnVar = army2_;
else if( army == 2 ) returnVar = army3_;
else if( army == 3 ) returnVar = army4_;
else if( army == 4 ) returnVar = army5_;
else if( army == 5 ) returnVar = army6_;
else if( army == 6 ) returnVar = army7_;
else if( army == 7 ) returnVar = army8_;
else returnVar = new Array;
return returnVar;
}
SkirmishScreen/returnArmy
public function returnArmy ( army_:int ):Array
{
var retArmy:Array = returnArmy( army_ );
return retArmy;
}
SkirmishScreen/returnArmy gets called in a loop, with
screensAR_[3] = new PlayScreen( stage, screensAR_[2].returnArmy( 0 ) );
with army1_ to 8_ initialized with new Array(). Anyone can help?
EDIT: The precise error is:
Error: Error #1023: Stack overflow occurred. at SkirmishScreen/returnArmy()
Upvotes: 0
Views: 181
Reputation: 9190
I'm not familiar with actionscript, but it looks like the "SkirmishScreen" returnArmy function is calling itself recursively, and never breaking out of it. This is a common source of stack overflow exceptions in other languages.
It doesn't appear like you mean to be using recursion. I'm guessing you want your "SkirmishScreen" returnArmy function to call the "ScrollList" returnArmy function, but instead the "SkirmishScreen" returnArmy is calling itself. That is recursion.
Upvotes: 2