Make your own free website on

Over-ride the recursive and timeout limit MX2004
by ericlin

The new tag: scriptLimits

To prevent crash, Flash by default allows only 256 depths of recursive call. This successfully screens out infinite loop. It is wise not to disturb this safety check. 

Sometimes we do need a deeper recursive calls. If we compile and run our swf, the script is aborted when the recursive depth gets to 256. The call is aborted without warning or error message popup.

How could we over-ride the limit of 256 ?

After Flash 7, the limit of recursive call can be over-ridden. A new tag "scriptLimits" is provided. 


Field Type Comment
Header RECORDHEADER Tag type = 65
MaxRecursionDepth UI16 Maximum recursion depth
ScriptTimeoutSeconds UI16 Maximum ActionScript processing time before script stuck dialog box displays

By setting these field, we can over-ride the recursive limit and timeout seconds.

However, there is no such panel item in Flash IDE environment. The only way seems to modify the compiled SWF through third party software.

Test movie

Well, we surely can modify our finished finally compiled SWF to get rid of the 256 limits before we handle the swf to the client. But, how could we test our recursive function before we are satisfied with our script ? During test movie, a new compiled SWF is produced for playing.  In other word, how could we over-ride the limit during "test movie" ? 

No way.

If we can not test our recursive function then the over-riding would be nearly nonsense. 

Here is a walk around.

In the first frame, we load a small movie that over-ride the recursive limits. Since the over-riding is global, we can test our recursive functions then without the limit of 256.

Now, let's create a small movie that over-ride the limit.

The small movie

Create a blank movie containing nothing. I set the document width and height as 20x20. The compiled swf is very small and is in uncompressed form. Dump the bytes by hex editor, it reads as below:

00000000 46 57 53 07 1B 00 00 00 50 00 C8 00 0C 80 00 0C FWS.....P.?.?..
00000010 01 00 43 02 FF FF FF 40 00 00 00 ..C.@...

The first 4 bytes are "FWS" and version number "7". What follows is the file size of this SWF : 0x0000001B. 

At the end of the file, we see 2 bytes  00-00 . This is the "end tag" of SWF.

I am going to plug the scriptLimits record into the swf file.  Lets change MaxRecursionDepth from the default 0x00FF to 0xFFFF, so the bytes should be FF-FF;  If we want to change the depth to 0x123, then the bytes would be 03-12. Lets also set ScriptTimeoutSeconds as 0xFFFF, so the bytes should be FF-FF; This record contains only these two fields. So the length of this block is 4 bytes. 

To calculate the RECORDHEADER, we do " (tag<<6)+block_length". The result is 0x1044; So, we need to plug this record:


It is convenient to plug this before the endTag.

Finally, we get to correct the file length. We add 6 bytes to the original length. Here we change the bytes from 1B-00-00-00 to 21-00-00-00.

The result:

00000000 46 57 53 07 21 00 00 00 50 00 C8 00 0C 80 00 0C FWS.....P.?.?..
00000010 01 00 43 02 FF FF FF 40 00 44 10 FF FF FF FF 00  . ..C.@.D...C.@...
00000020 00

This movie will over-ride the recursive limit and timeout limits.


Here is a test movie. The 256 limit is over-ridden if we load that small movie.

download the files to test

Here is a limitation. When the movie is played on line, the timing that the small movie get load in is not predictable. The over-ridden effect only appear when that small movie is loaded. If our recursive function is executed at the first frame, it is likely to fail.

Anyway, if we are satisfied with our end result, we remove that line and modify our end resulted SWF by third party software. Surely we can use the same principle to enable our SWF to over-ride the recursive limit. However, most of the SWF published are in compressed form. WE need to uncompress it, modify it and re-compress it back.

Here we discussed about over-ridding the recursive limit. Of-course, we can also over-ride the timeout limit. We can also "reduce" the timeout or limit the recursive depth to 8 only by this method.

email :