08.19.07

Flash/Flex AS3 Error #1023: Stack overflow occurred.

Posted in errors, Flash, Flex, Loops at 11:54 pm by Curtis J. Morley

Error #1023: Stack overflow occurred

at MyClass/get id()

Description:
This will happen if the stack has so much data that it is full. Nothing like Thanksgiving dinner to overflow my stack.  What is a stack and how does it get full you ask. Simply put each method(function) has a stack and that stack stores data associated with the method such as local variables with the method. Although it is a good idea to understand what a stack is you really you don't need to have an in depth understanding of stacks to understand this error and it's solution. Basically this error is saying that you are most likely calling the function recursively. Or in other words you might be calling the function from within itself.

Solution:
To rid yourself of ActionScipt error 1023 make sure that you don't call the method from within itself which will eliminate any type of recursion in your method call. You may be tempted to do this by setting a variable name the same as the function name. Change either one and this will go away. Notice in the 'Bad Code1' example that each time the getter returns what you think is an 'int' you actually are calling the setter function again recursively. The trace statement will also produce AS3 Error #1023

Bad Code1:

public function set id (myId:int):void
{
this._id = id;
}
public function get id ():int
{
trace("this.id",this.id);
return this.id;
}

Good Code1:

public function get id ():int
{
trace("this.myId",this.myId);
return this.myId;
}

Bad Code2:

private function recursiveLoop ():void
{
recursiveLoop ();
}

Good Code2:

private function noRecursion():void
{
someOtheFunction ();
}

Adobe actually has a reasonable explanation for this error in liveDocs. Here is a link to the Adobe page that explains ActionScript Error 1023

As always Happy Flashing

14 Comments »

  1. Daniele Giardini said,

    August 29, 2007 at 8:26 pm

    Hi Curtis,

    I found your site while searching around for help with error 1023. While coding it happened to me the strangest thing, and i’m quite sure this is a naughty but…
    Try to open a new AS3 FLA file, and write in the Actions Panel this simple code:

    function someFunc(x1:String, x2:String, x3:Number=0):String
    {
    var my_result:String = “result”;
    return my_result;
    }
    someFunc(“someVal1″, “someVal2″);

    Calling someFunc will call a stack overflow error!!! The only way not to have it is to remove the “x3″ Parameter. That’s sooooooo strange (and annoying, ’cause before realizing this was a bug i was getting crazy trying to find an error in my original code, which was much more complex).

    P.S. i’m using FlashPlayer debugging version 9.0.r47, i hope it’s his fault

    Kind regards & a nice day,

    Daniele

  2. Curtis J. Morley said,

    August 29, 2007 at 11:37 pm

    Daniele,

    Is there anything else in your code labeled ‘x3′. A method perhaps? If so, this may be why you are getting this error. If not, I would love to see your file help you find out why you are getting AS3 Error 1023 it could be.

    Thanks,
    Curtis J. Morley

  3. Daniele Giardini said,

    August 30, 2007 at 9:11 am

    Hi Curtis,

    I’m thankful for the help, but I tried it with no other code to be sure it was a bug, and that AS I wrote you is the stripped out version I finally reached.
    Just copy&paste the ActionScript I wrote in a new AS3 FLA (without anything else) and you should get the error… Straaaaaaaaange.

    Thanks & regards :-)

    Daniele

  4. Daniele Giardini said,

    August 30, 2007 at 9:50 am

    P.S. it suffices to add something between “my_result” declaration and the function return, not to get this error, like:

    var my_result:String = “result”;
    var someVar:String = “”;
    return my_result;

    And this makes this bug even more queer :-)

  5. Curtis J. Morley said,

    September 3, 2007 at 5:29 pm

    Daniele,

    I find that every time I run into a wall I copy the ActionScript into a text editor and then paste the exact same ActionScript back into Flash/Flex. This has solved the problem for me about 8 times now. I have had other friends say the same thing. If they copy and paste the ActionScript without changing anything it will often resolve the problem.

    Thanks for reading and Happy Flashing
    Curtis J Morley

  6. Daniele Giardini said,

    September 11, 2007 at 7:10 pm

    Oh wow (stayed outta town for a job, thus i’m reading what you last wrote just now). I’m afraid that won’t solve that particular bug, cause my original code was in an external class written with FlashDevelop. But anyway, it’s really a great suggestion: i never thought about that. Thanks, every time i’ll have issues inside Flash i’ll remember you :-)

    Thanks for answering & nice days :-)

    Daniele

  7. thomas said,

    December 28, 2007 at 2:42 pm

    Hey Curtis,

    I just tried that copy out and back into flash trick, and it worked like a CHARM!
    thanks a bunch, I was beginning to doubt my sanity.

    Thomas

  8. Eric Belair said,

    January 18, 2008 at 11:20 pm

    I do not have a recursive function, but I am getting this error.

    Copy and Paste is not working for me. I get the error in FB3 when I do a “Export Release Version”, but not when I simply do a “Build Project”.

    Here is the code for the function that is giving me this error:

    // Handle results of Widget Columns WebService
    private function sWidgetColumnsResult(_wsResultEvent:wsResultEvent):void
    {
    // Store the WebService results as an Array Collection
    var result:ArrayCollection = _wsResultEvent.result as ArrayCollection;

    // Loop through the WebService results Array Collection
    for each (var object:Object in result)
    {
    // Store the Object as a Widget Column Class Instance
    var widgetColumn:WidgetColumn = new WidgetColumn(object);

    // Set the Widget Column’s Default Display Code to the index of the loop
    widgetColumn.PARAMVALUEDISPLAYCODE = widgetColumn.DISPLAYCODE;

    // Add the Widget Column Object to the Array Collection of all Widget Columns
    widgetColumns.addItem(widgetColumn);
    }
    }

    I’ve tried changing the code to do the loop different ways, but I still get th same error. Any ideas?

    Thanks.

  9. Leonardo Zimbres said,

    July 30, 2008 at 12:42 pm

    Thanks Curtis, your post helped me today.

  10. Curtis J. Morley said,

    August 1, 2008 at 10:32 pm

    Leonardo,

    Glad I could help resolve AS3 Error 1023 for you.

    Thanks,
    Curtis J. Morley

  11. Hussein said,

    November 30, 2009 at 6:12 am

    i have done a blackjack game its written in as3.I’m getting Error: Error #1023: Stack overflow occurred.
    after i play so many time.this the function were i think its doing the issue.

    function calculateScore(player:Array, score:uint):uint
    {
    for(var i:uint = 0; i < player.length; i++)
    {
    if(player[i].cardName == “Ace” && getTotalScore(player) 21)
    {
    player[i].cardValue = 1;
    }
    }
    score = getTotalScore(player);
    if(player == dealerCards && score <= 16)
    {
    makeCard(dealerCards, dealerContainer);
    calculateScore(dealerCards, dealerScore);
    }
    return score;
    }

    thank you

  12. Hadi said,

    April 11, 2010 at 1:04 am

    You saved my day :) Thanks a lot for sharing.

  13. deepak said,

    September 7, 2010 at 11:14 pm

    Please help me out

    I am fresher to Flex. i wrote this application for make a brid image fly but i am not able to solve this error as i don’t have anyone with me.. so pleas help me out….

    Thanks in Advance….
    Deepak
    deepak.dynamite@gmail.com

  14. John Yaple said,

    April 27, 2012 at 7:39 pm

    I had this error happen when I tried to make a function that consisted of the following code.

    public function circleVsConcaveVertex(circX:Number, circY:Number, circRad:Number, vertex:AVectorModelData, pEdge:AVectorModelData, nEdge:AVectorModelData):TupleNum
    {
    var tuple:TupleNum = new TupleNum();

    return tuple;
    }

    It is very odd, as if I modify the function to do something such as perform a trace operation or any form of other function body the function will run just fine.

Leave a Comment