Professional Web Applications Themes

256 levels of recursion?? - Macromedia Flash Actionscript

I've just started trying to write some games in flash. It seemed the ideal language since it's cross platform, ubiquitous and highly functional. However, after banging my head against problems for the last day and a half I'm starting to get frustrated with the language. There are all these annoying limitations. The two that have given me the biggest problems so far are the inability to trap and use right click events (without that damn menu appearing) and just now I've run over something that seems even more implausable - the 256 levels of recursion limit. Now I fully understand ...

  1. #1

    Default 256 levels of recursion??

    I've just started trying to write some games in flash. It seemed the ideal
    language since it's cross platform, ubiquitous and highly functional.

    However, after banging my head against problems for the last day and a half
    I'm starting to get frustrated with the language. There are all these annoying
    limitations. The two that have given me the biggest problems so far are the
    inability to trap and use right click events (without that damn menu appearing)
    and just now I've run over something that seems even more implausable - the 256
    levels of recursion limit.

    Now I fully understand *why* Macromedia put this limit in, it's to protect
    programmers from their own mistakes, but (a) 256 levels is FAR too few and (b)
    it should be something that competent programmers can turn off.

    PLEASE start treating flash like a professional language if you want
    professional programmers to start using it for real applications. If you
    continue to restrict the language's capabilities in this way Flash will forever
    remain a pretty looking toy.

    John

    floyduk Guest

  2. #2

    Default Re: 256 levels of recursion??

    "floyduk" <webforumsusermacromedia.com> wrote
    > and just now I've run over something that seems even more implausable -
    > the 256 levels of recursion limit.
    >
    > Now I fully understand *why* Macromedia put this limit in, it's to
    > protect programmers from their own mistakes, but (a) 256 levels is
    > FAR too few and (b) it should be something that competent
    > programmers can turn off.
    Anything involving that many levels of recursion will be much faster and use
    much less memory if done non-recursively.




    Ivan Peters Guest

  3. #3

    Default Re: 256 levels of recursion??

    > Anything involving that many levels of recursion will be much faster and
    use
    > much less memory if done non-recursively.
    Can you give us an example of converting a recursive function into a non
    recursive function?


    Mark Redman Guest

  4. #4

    Default Re: 256 levels of recursion??

    > Anything involving that many levels of recursion will be much faster and use
    > much less memory if done non-recursively.
    Using less memory perhaps but not faster. Entertaining as it is for you to
    presume about what I'm trying to achieve there are times when recursion is a
    valuable tool.

    John

    floyduk Guest

  5. #5

    Default Re: 256 levels of recursion??

    "Mark Redman" <co.uk> wrote 

    Walking a tree depth first.

    Recursive:

    function walkNode(currentNode:Object) {
    trace(currentNode.name);
    for (i:Number = 0; i < currentNode.numChildren; i++) {
    walkNode(currentNode.children[i]);
    }
    }


    Non-recursive:

    function walkTree(theTree:Object) {
    var nodeStack:Array = new Array;
    var indexStack:Array = new Array;

    trace(theTree.name);
    var currentNode:Object = theTree;
    var currentIndex:Number = 0;
    var done:Boolean = false;

    while (!done) {
    trace(currentNode.children[currentIndex].name);
    if (currentNode.children[currentIndex].numChildren > 0) {
    nodeStack.push(currentNode);
    indexStack.push(currentIndex);
    currentNode = currentNode.children[currentIndex];
    currentIndex = 0;
    } else {
    currentIndex++;
    while (currentIndex >= currentNode.numChildren) {
    if (nodeStack.length == 0) {
    done = true;
    } else {
    currentNode = nodeStack.pop();
    currentIndex = indexStack.pop() + 1;
    }
    }
    }
    }
    }

    (The array code could be optimised for better performance but this keeps it
    readable)

    It's certainly not easy and I wouldn't bother doing it unless I had a
    specific reason (memory/performance problems or a recursion limit in the
    language). Any performance/memory improvements in the above example are
    pretty dubious, but anything involving more complex processing of each node
    may well benefit when the number of recursions gets high.


    Ivan Guest

  6. #6

    Default Re: 256 levels of recursion??

    256 is generally an acceptable depth for the return stack John.

    If you are that deep into the recursion call, you might want to step back and
    rethink it. Its true that recursion can greatly reduce and simplify your code,
    but in this case I agree with the suggestion of looping.

    Also.. I would hardly call flash an "ideal language" (hehe). (I speak
    several). It's far too slow and it's multitasking is quite unpredictable.

    oopiewanCodeknowbie Guest

Similar Threads

  1. Syntax for end recursion
    By Robert.Koepferl@de.gi-de.com in forum Ruby
    Replies: 4
    Last Post: July 25th, 10:11 AM
  2. Is Recursion Allowed?
    By DaveHCYJ in forum Coldfusion - Advanced Techniques
    Replies: 2
    Last Post: May 16th, 04:29 PM
  3. Help: "256 levels of recursion were exceeded in one action list."
    By Roald Fernandez in forum Macromedia Flash
    Replies: 4
    Last Post: September 6th, 04:18 PM
  4. Size of dir (with recursion)
    By Jesper Noehr in forum PERL Beginners
    Replies: 4
    Last Post: December 29th, 11:08 PM
  5. Recursion
    By Jeff Westman in forum PERL Beginners
    Replies: 15
    Last Post: November 4th, 12:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139