I have a script that creates a grid of squares and fades random ones. But the problem is this: when I test the movie, everything seems fine. When I test it again, it gives an error. But I didn’t change anything ! I do use random(), so I guess that causes the error at certain values. This is the error it gives me:
256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie.
But the weird thing is that (as already said) this error occurs randomly. And; it only occurs when a few (1 - 4) boxes are remaining.
This is the script I used:
[AS]
gridx = 27.7;
gridy = 27.7;
num = 0;
azcount = 0;
amH = 11
amV = 8
lastrandom = 0;
for (var i = 0; i<amH; i++) {
for (var j = 0; j<amV; j++) {
dot.duplicateMovieClip(“dot”+num, num);
mc = this[“dot”+num];
mc._x = 100+(gridxi);
mc._y = 100+(gridyj);
num++;
}
}
_root.dot._visible = 0;
//
//
// End of grid
//
//
function continueFade(mc, speed) {
mc.onEnterFrame = function() {
mc._alpha -= speed;
if (mc._alpha<=0) {
delete mc.onEnterFrame;
}
};
}
function fadeMC(mcnr, speed) {
_root.lastrandom = mcnr
if (_root[“dot”+mcnr]._alpha == 100) {
_root[“dot”+mcnr].onEnterFrame = function() {
_root[“dot”+mcnr]._alpha -= speed;
if (_root[“dot”+mcnr]._alpha<=50) {
_root[“dot”+mcnr].onEnterFrame = null;
azcount++;
continueFade(_root[“dot”+mcnr], speed);
/mcnr += 1;/
fadeOut(speed);
}
};
} else {
if (azcount<(amH*amV)) {
fadeOut(speed);
}
}
}
function fadeOut(speed) {
random = Math.floor(random(100))
if(random == lastrandom){
fadeOut(speed)
} else {
fadeMC(random, speed);
}
}
fadeOut(10);
[/AS]
Are you doing Ctrl+Enter twice? first time works, then second run acts funny?
If so, i’ve also had problems similar to yours. This is a problem in flash. Sometimes it seems when you run an SWF again, some things don’t get resetted. When you create your SWF, it should work fine (as long as it worked fine the first time:)) in a browser.
*Originally posted by claudio *
**One thing i noticed: you are using a variable with the name random. Words used by ActionScript should never be used as variable names. **
I’ve noticed that too, but i used some keywords in the past and they didn’t seem to affect the movie as much. I guess using random might be a different story. But yeah, like claudio said, you should try to name your variables something unique.
Are you doing Ctrl+Enter twice? first time works, then second run acts funny?
No, I Ctrl+Enter once, then close the swf and then CTRL+Enter again.
If so, i’ve also had problems similar to yours. This is a problem in flash. Sometimes it seems when you run an SWF again, some things don’t get resetted. When you create your SWF, it should work fine (as long as it worked fine the first time) in a browser.
That could be a possible explanation. But I’m kinda afraid to test it online because if it goes into an infinite loop online, my pc would freeze.
One thing i noticed: you are using a variable with the name random. Words used by ActionScript should never be used as variable names.
I changed random to rnd, but it still doesn’t work. Good suggestion though Claudio I should keep that in mind.
So … I guess I’l just have to test it online and see what happens. Hope my pc doesn’t freeze saves all Flash documents.
Hey thor, I guess you were right. I open the file, test it. It works. I close the swf, test again, it doesn’t work. close again, test again, doesn’t work. Close again, change the AS a little bit, test it, works. Close swf, test it, doesn’t work. Close swf, test it, doesn’t work…
So I guess it only works after I’ve changed the AS and when testing after opening the file. Which means that it should work online. I’m gonna test it right away.
tell me exactly what you’re trying to do and i’ll write the code for you. this seems very odd and i’d hate to see someone lose it (go nuts) over something that may be someone else’s flaw.
Thanks thor. This code creates a grid, and fades a random box out, and when that box reaches alpha 90 is fades another random box out. I’ve uploaded the swf, you can view it here. Don’t worry, the infinite loop didn’t freeze my pc so I suppose it won’t freeze yours either.
The whole doesn’t work/work is totally random, so there has to be something wrong in the code. But I can’t figure out what !
Oh wait, random(100) includes 100 right ? Then it might be possible, that I have to set random(100) to random(amH*amV) since my boxes start at box0 and end at box87 (amH = 8, amV = 11)
pos = 0;
rows = 5;
cols = 5;
size = 15;
offsetX = 550/2-(cols*size)/2;
offsetY = 400/2-(rows*size)/2;
var index, mc;
Array.prototype.randomize = function() {
var num, numVal;
for (var i = 0; i<this.length; ++i) {
num = random(this.length);
numVal = this*;
this* = this[num];
this[num] = numVal;
}
};
MovieClip.prototype.createBox = function(name, depth, sze) {
var mc = createEmptyMovieClip(name, depth);
with (mc) {
lineStyle(0, 0, 100);
beginFill(0);
moveTo(0, 0);
lineTo(sze, 0);
lineTo(sze, sze);
lineTo(0, sze);
lineTo(0, 0);
endFill();
}
return mc;
};
MCs = [];
for (var i = 0; i<rows; ++i) {
for (var j = 0; j<cols; ++j) {
index = i*rows+j;
MCs[index] = mc=createBox("box"+index, index, size);
mc._x = offsetX+j*size;
mc._y = offsetY+i*size;
mc._alpha = 0;
}
}
MCs.randomize();
onEnterFrame = function () {
MCs[pos].onEnterFrame = function() {
this._alpha += 15;
if (this._alpha>100) {
delete this.onEnterFrame;
}
};
if (MCs[pos]._alpha>=90) {
++pos;
}
if (pos>=rows*cols) {
delete this.onEnterFrame;
}
};
Just change all the necessary variables. I notice in your example you are using this as a mask. Instead of using the createBox function I have, just replace that with whatever you’re using.
*Originally posted by Voetsjoeba * Oh wait, random(100) includes 100 right ?
Nope, random(100) returns an integer between 0 and 99 (0 and 99 included).